- Home /
Question by
gameromen12 · Apr 05, 2018 at 08:08 PM ·
rotationgameobjectgameobjectsvaluegame over
I wanted to make the game over if the player rotation is some value
its the game object that if he rotate on z the game ends
Comment
Answer by megamika2 · Apr 05, 2018 at 08:21 PM
You can try this script. using System.Collections; using System.Collections.Generic; using UnityEngine;
public class Example : MonoBehaviour {
public float UpdateFrequency;
private void Start()
{
StartCoroutine(rotationChecker());
}
IEnumerator rotationChecker()
{
float previousRotation = transform.rotation.z;
yield return new WaitForSeconds(UpdateFrequency);
float RotationDiference = previousRotation - transform.rotation.z;
if (RotationDiference != 0)
{
//GameOverHappens
}
else
StartCoroutine(rotationChecker());
}
}
Here I am basically checking if z value has changed over the period of time that you chose and if yes game over happens if no it checks again.
Your answer

Follow this Question
Related Questions
Cannot rotate a triangle shape! 1 Answer
Rotate an Object by a spezific value 2 Answers
Rigidbody Disable Velocity/Movement? 1 Answer
Position and rotation of a game object acting wired 0 Answers