Hello! I am getting an error when I try to find the length of an array! All I am trying to accomplish with this script is spawn a random gameobject from an array. To do that I need to find the length of an array, yet for some reason Unity won’t let me do that. The error I am getting is: CS0117 UnityEngine.GameObject[] does not contain a definition for 'Length'
Here is my code, also note I have tried to just print the length of the array to the console out of the instantiate and just in the start function, it resulted in the same error.
using UnityEngine;
using System.Collections;
public class SpawnScript : MonoBehaviour {
public GameObject[] objects;
// runs spawn func
void Start () {
Spawn();
}
//spawns in a random item from an array and then does it every .5 seconds.
void Spawn()
{
Instantiate(objects[Random.Range (0, objects.Length)], transform.position, Quaternion.identity);
Invoke ("Spawn", .5f);
}
}
Thanks for viewing (and hopefully helping)!