I’ve got the following code
public GameObject currentObject;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if (currentObject != null)
{
//Do stuff
}
}
public void SpawnObject(GameObject gameObject)
{
if (currentObject == null)
{
currentObject = Instantiate(gameObject);
}
}
The SpawnObject is called on a button click and adds a gameobject. When I click the button the gameobject is instaniated and I can see it in my scene but in the next update the currentObject variable is null and I can’t see why that would be.
Any help in spotting what I’m missing would be much appreciated.