Hi all, I have recently moved into C# scripting from JavaScript and I would like to know if there is a way of controlling an object in C# so that it will be hidden when the scene starts but will then appear when a collision occurs? This is the script I currently have:
using UnityEngine;
using System.Collections;
public class collideEnemy : MonoBehaviour {
void Start () {
Destroy(GameObject.Find("Cog"));
}
void OnTriggerEnter(Collider other) {
Destroy(GameObject.Find("Enemy"), 1);
Instantiate(GameObject.Find("Cog"));
}
}
I was trying to accomplish what I wanted to do with the destroy and instantiate functions, however this gives me a “NullReferenceException” error, I’m guessing because the item I’m trying to Instantiate is already destroyed. Is there another way to do this, or a way around this? I was thinking of calling the function from another script but I’m unsure how to do this in C# or if this would even work. I’d appreciate any help!