I need help on stopping a rotation when it makes a 180 when i activate a coroutine for the first time, then whenever i activate the coroutine again, to go another 180 and not to glitch back to the original 180. I scoured this code for an hour trying different things, and i can’t find whats wrong with it and quite frankly, I’m stumped. This is what i have come up with.
void Start()
{
RotationDegree = 0;
Rotating = false;
Rot = false;
Rotatingto = 0;
RotationDegreeAdded = 180;
}
void OnCollisionEnter(Collision C)
{
RotationDegree = RotationDegree + RotationDegreeAdded;
Rotatingto = RotationDegree;
Rotating = true;
StartCoroutine (MyMethod ());
//Debug.Log ("Rotation Begun");
}
void Update()
{
if (Rotating) {
Vector3 RotationVector= new Vector3 (0.0f, 0.0f, RotationDegree);
Background.transform.Rotate (RotationVector * (Time.deltaTime));
Goals.transform.Rotate (RotationVector * (Time.deltaTime));
}
Debug.Log (RotationDegreeAdded);
Debug.Log (RotationDegree);
}
IEnumerator MyMethod(){
yield return new WaitForSeconds (1);
//Debug.Log ("Rotation Over");
Background.transform.rotation = Quaternion.Euler (0.0f, 0.0f, Rotatingto);
Goals.transform.rotation = Quaternion.Euler (0.0f, 0.0f, Rotatingto);
if (RotationDegree == 180) {
RotationDegree = 0;
RotationDegreeAdded = 360;
}
if (RotationDegree == 360) {
RotationDegree = 0;
RotationDegreeAdded = 180;
}
}