Hey, so i want to instantiate a random object in to the scene, so im using arrays. But it doesnt seem to work, it only instantiate the first object in the array. Whats the problem? -Thanks! ) Script: Code (csharp): public Transform[] BloodSplatter; Instantiate(BloodSplatter[Random.Range(0, 1)], new Vector3(Random.Range(0.04f, 0.97f), Random.Range(0.94f, 0.07f), 0), transform.rotation);
Random.Range (0, 1) will only ever return 0, since the max value is exclusive. Anyway you should not hard-code values, but use the array length. i.e., bloodSplatter.Length. --Eric
As Eric5h5 said, this way it'll work for any size array. Code (csharp): public Transform[] BloodSplatter; Instantiate(BloodSplatter[Random.Range(0, BloodSplatter.Length)], new Vector3(Random.Range(0.04f, 0.97f), Random.Range(0.94f, 0.07f), 0), transform.rotation);