I'm new to C#. I have a nested if statement, and on the first if one of the conditions is activating the else then when it shouldn't.
if (transform.position.y > 10 ||
transform.position.y < -10 ||
transform.position.x > 10 ||
transform.position.x < -10 ||
_timeSittingAround >= 3)
{
if (lives > 0)
{
transform.position = _initialPosition;
GetComponent<Rigidbody2D>().gravityScale = 0;
GetComponent<Rigidbody2D>().velocity = new Vector3(0, 0, 0);
_birdWasLaunched = false;
lives--;
}
else
{
string currentSceneName = SceneManager.GetActiveScene().name;
SceneManager.LoadScene(currentSceneName);
}
}
When _timeSittingAround >= 3 the scene is reloaded by the else then, and I cannot for the life of me figure out what could possibly be wrong.
When the scene plays if the player leaves the
(transform.position.y > 10 ||
transform.position.y < -10 ||
transform.position.x > 10 ||
transform.position.x < -10 ||
box they are returned to the initial position and the level continues. However if the player is still for the
_timeSittingAround >= 3
then the entire scene is reset not just the player object.
Aucun commentaire:
Enregistrer un commentaire