One more thing I noticed that I wanted to give feedback on - there's a block of code that you repeat that would work well as a separate "utility" method. I also noticed that you didn't connect the two `if` statements with an `else`. This is a good idea in your case because a GameObject can only have one tag, so if it has one, it definitely doesn't have the other. Using an `else` means that the code won't waste time checking the other one. Combining those two ideas, you could do something like this:
if (collision.gameObject.tag == "End")
{
ResetGame();
}
else if (collision.gameObject.tag == "Dess")
{
ResetGame();
}And then just move the code that was there previously into a separate `ResetGame` method:
private void ResetGame() {
moving = false;
Debug.Log("You won! Press X to play again!");
rb.velocity = Vector3.zero;
transform.position = new Vector3(1.95f, 0.5f, 0);
speed = 0;
timerIsRunning = false;
timeRemaining = 30;
}
Does that make sense?
Leave a comment
Log in with itch.io to leave a comment.