- Home /
Help with array collision script !
I'm making a turn based game were the basic movement is "select a cell and then then move to it". But the player needs to know which "cells" he can move to. To find the "Cell" I made a sphere collider that when colliding with an object with the tag "Cell" it adds it to an array of objects. But i'm stuck on a problem. I need the sphere to remove the "Cell" that stopped colliding with it from the array. Could anyone help me do this? Here's my script:
`
var cellArray = new Array (); var i : int = 1;
function Start (){
}
function OnTriggerEnter (collision : Collider) {
if (collision.gameObject.tag == "Cell"){
for(var g in cellArray){
i++;
}
cellArray.Push(collision.gameObject);
Debug.Log("Added " + collision.gameObject + " to list");
i = 0;
Debug.Log(cellArray.length);
}
}
function OnTriggerExit(collision : Collider) {
if(collision.gameObject.tag == "Cell"){
var h = collision.gameObject;
for( h in cellArray){
i++;
}
cellArray.RemoveAt(i);
Debug.Log("Removed " + collision.gameObject + " from list");
Debug.Log("Now there are " + cellArray.length + " objects in the array");
}
}
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Setting up an array of tags. 2 Answers
Broken scripts(need help fixing) 1 Answer
Help on Player Movement Script C# 1 Answer