I'm trying to make a gameover-text show when the player is leaving the plane-area. In GameManager.cs I've written:
public void GameOver()
{
gameOverText.gameObject.SetActive(true);
}
And in PlayerController.cs I've used the following code:
private GameManager gameManager;
and:
void Update()
{
float horizontalInput = Input.GetAxis("Horizontal");
float verticalInput = Input.GetAxis("Vertical");
playerRb.AddForce(Vector3.right * speed * horizontalInput);
playerRb.AddForce(Vector3.forward * speed * verticalInput);
if (transform.position.y < -4)
{
gameManager.GameOver();
}
}
But this doesn't really work, and the console is giving me this message:
Assets/Scripts/PlayerController.cs(8,25): warning CS0649: Field 'PlayerController.gameManager' is never assigned to, and will always have its default value null
I've already used the OnTriggerEnter
(for powerups) and OnCollisionEnter
(for enemies). How can I get the GameOver-text to show when the player leaves the "Plane"?
GameManager
script instance will get populated into yourprivate GameManager gameManager
variable? Remember this variable will hold a value of "null" until you put something there, either by assigning it in your script, or exposing it as a field you can populate in the Inspector UI. So, what's your strategy for wiring up this value? \$\endgroup\$