Assign the player GameObject in the Inspector by script

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]
	}
}

I am not understanding your question.

Can you explain some more :slight_smile:

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.

oh well when you want to change it just put player = someObject; and it will change it to that object

Ok thank, I was not able to do it because “hit” is a Collider.
Like this it work!
player = hit.gameObject;