Hello,
I wrote a script to find an object in the world, but something not working right. Here my code:
public class GameManager : MonoBehaviour {
private GameObject playerObject;
private Player player;
void Awake()
{
GameObject playerObject = GameObject.Find("Player");
}
void Start()
{
player = playerObject.GetComponent<Player>();
}
}
But I get a NullPointerException in the player = playerObject.GetComponent<Player>();
line. I can see the player object in the scene view. What’s wrong?