- Home /
Im trying to instantiate prefab from an array but get a confusing response...(this prefab will be consumed by the player meaning it needs to be instantiated multiple times)
public class ChaseRabbit : MonoBehaviour { private Transform position; public GameObject[] vegArray; public int vegLimit = 10; public GameObject veg;
void Start()
{
Vector3 position = new Vector3(Random.Range(0.0f, 50.0f), 0, Random.Range(0.0f, 50.0f));
vegArray = new GameObject[vegLimit];
}
void Update()
`{ for (intI =0; I<vegLimit;i++) { vegArray[i] = Instantiate (veg, position, Quaternion.identity) as GameObject;
//Here I am told that "Cannot convert UnityEngine.Quaternion to "bool"" any ideas?? } }
Answer by andrew-lukasik · Jul 24, 2017 at 11:29 PM
Mind the overloads:
Answer by Cockwork_Crewdy · Jul 26, 2017 at 06:59 PM
I realised I had to put the random range in the update function
No. This is not the problem. You declared field with name "position" twice:
private Transform position;
Vector3 position
And by doing so you lost track of which one compiler decided to use in Instantiate call. Just don't name Transforms as "position" or something similarly misguiding and everything will be much clearer.