Hi
I have two scripts, PlayerController.cs and Target.cs in PlayerController there is a public GameObject target;
In Target.cs I want to set the gameobject I click as target in the PlayerController script, but obviously I messed up somewhere.. anyone have a hint?
The first line works just fine as far as I can see. Debug.Log prints out the name of the object I click. I am also able to access target and other int's etc from the PlayerController using pc. so I guess the third line works? However I cant set the target of PlayerController to "go"
Error: NullReferenceException: Object reference not set to an instance of an object
Target.cs
void OnMouseDown() {
GameObject go = this.gameObject;
Debug.Log(go);
PlayerController pc = (PlayerController)GetComponent("PlayerController");
pc.target = go;
}
Anyway, thanks for looking