I have a GameObject array. I’m trying to remove objects from it based on trigger. But the compiler recognises it as a GameObject and not an array. How do I convert the GameObject into an array? Here’s the code:
var tileArray : GameObject[];
var speed : float = 5;
var x : float;
var z : float;
var tile : GameObject;
function Update () {
x = Input.GetAxis("Horizontal") * speed * Time.deltaTime;
z = Input.GetAxis("Vertical") * speed * Time.deltaTime;
transform.Translate(x, 0, z);
//Debug.Log("Position is " + transform.position.x + " " + transform.position.y + " "+ transform.position.z);
}
function OnTriggerEnter (other : Collider) {
//Debug.Log("Triggered! " + other.gameObject.transform.position);
tileArray += [other.gameObject];
}
function OnTriggerExit (other : Collider) {
for (var i = 0; i < tileArray.length; i++)
{
if (tileArray *== other)*
-
tileArray.RemoveAt(i); // Problem part*
- } *
}
It throws me the following error:
Assets/Scripts/CharacterMove.js(33,35): BCE0019: ‘RemoveAt’ is not a member of ‘UnityEngine.GameObject[]’.
Thanks in advance.