I’m sorry but I found it hard to get a good title for what I’m looking for. So, basically I want to assign a gameObject in the script. This is my current script:
public TestHealth playerScript;
private GameObject Player;
void Start() {
playerScript = Player.GetComponent<TestHealth>();
}
public void OnCollisionEnter2D (Collision2D other) {
if(other.gameObject.name == "Player") {
Debug.Log ("BONK");
playerScript.curhp -= 10;
}
}
How can I assign “Player” to playerScript? When I do this by hand in the Unity interface, the game and function works, but I get an error message with a null reference to a gameObject, like the Player object was not assigned. But I believe this is only for the first frame or something. It is really annoying. I would love some insight on this!
Sorry for my lack of experience and depth, I am working hard to improve