I am very noob at unity and was trying to make a script where the player dies everytime it touches a certain object. However, in the program, the variable “player” always returns a value of null. The game object “Character” is independent of the object to which this script is attached. Please excuse if this is an extremely basic question, I have searched around and could not find solutions which work.
“Character” is active and is neither a parent nor a child of the object.
GameObject player;
void Start () {
GameObject player = GameObject.Find ("Character");
}
void Update () {
Debug.Log (player);
}
void OnCollisionEnter(Collision col){
if (col.gameObject.name == "Character") {
player.GetComponent<PlayerScript>().die ();
}
}