Object A instantiates Object B on key press. Object A has a variable, which should add Object B clones to itself, each time key is pressed. I’m really confused as to how to achieve this. This script is attached to Object A. I assigned Radius(Clone) in the Inspector as well, but when I run the code, it changes to None(GameObject). I’m currently getting NullReferenceException. Here is my code.
public GameObject radiusPrefab;
void Start()
{
radiusPrefab = (GameObject)Instantiate (radiusPrefab);
radiusPrefab.SetActive(false);
}
void Update (){
if(Input.GetKeyDown(KeyCode.Z))
{
radiusPrefab = GameObject.Find ("Radius(Clone)");
radiusPrefab.SetActive(true);
}
}