Hi,
I am a pretty noob and it would be great if you help me with this problem. I am trying to instantiate projectiles randomly with an interval from one of three positions.
I get back the error: Object reference not set to an instance of an object.
This is my code:
public GameObject CanonA;
public GameObject CanonB;
public GameObject CanonC;
public GameObject projectile;
GameObject[] canons;
int index;
// Start is called before the first frame update
void Start()
{
canons[1] = CanonA;
canons[2] = CanonB;
canons[3] = CanonC;
}
// Update is called once per frame
void Update()
{
if (Input.GetMouseButtonDown(0))
{
index = Random.Range(0, 3);
Debug.Log(index);
Debug.Log(canons[index]);
Instantiate(projectile, canons[index].transform.position, canons[index].transform.rotation);
}
}