I’m trying to find the syntax to assign the player GameObject in the Inspector player variable?
Thank if anyone can help!
using UnityEngine;
using System.Collections;
public class MyScript: MonoBehaviour{
public GameObject player;
void OnTriggerEnter(Collider hit){
[COLOR="red"]player.gameObject = hit.gameObject;[/COLOR]
}
}
if its a public variable it will show up in the inspector. You drag the gameobject onto it. you dont need to put player.gameObject either, because it already is a gameObject
I understand I can drag the gameobject onto a public variable but I want to do it during gameplay using script.
Because I want this public GameObject variable to change during gameplay.