I am trying to make a flappy bird type game where when I die I get sent back to the menu. But when I click start again the player keeps the downward velocity from the round before making it impossible to regain control of the bird because it falls out of the scene almost immediately.
I´m getting this error when calling rigidbody:
Assets\Scripts\GameOver.cs(20,13): error CS0120: An object reference is required for the non-static field, method, or property ‘Rigidbody.velocity’.
This is my script to initiate game over:
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if (transform.position.y > 16 || transform.position.y < -7)
{
Rigidbody.velocity = Vector3.zero;
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex - 1);
}
}
private void OnCollisionEnter(Collision collision)
{
Rigidbody.velocity = Vector3.zero;
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex - 1);
}
}