I have the following bit of code run:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraFlip : MonoBehaviour {
[SerializeField]
private GameObject gameManager;
private GameManager gameManagerScript;
[SerializeField]
private GameObject player;
private Player playerScript;
[SerializeField]
private GameObject light;
[SerializeField]
private float tiltSpeed = 1f;
protected bool rotating;
private void Start() {
playerScript = player.GetComponent<Player>();
gameManagerScript = gameManager.GetComponent<GameManager>();
}
private void Update() {
Debug.Log(transform.localEulerAngles.y);
}
public void Rotate() {
if (transform.localEulerAngles.y == 0) {
StartCoroutine(FlipNormalToReverse());
playerScript.reversedControls = true;
} else if (transform.localEulerAngles.y == 180f) {
StartCoroutine(FlipReverseToNormal());
playerScript.reversedControls = false;
}
}
IEnumerator FlipNormalToReverse() {
while (transform.localEulerAngles.y <= 180f) {
transform.Rotate(Vector3.up, tiltSpeed);
light.transform.Rotate(Vector3.up, tiltSpeed);
rotating = true;
yield return new WaitForSeconds(0.1f);
}
if (transform.localEulerAngles.y == 180f) {
rotating = false;
}
}
IEnumerator FlipReverseToNormal() {
while (transform.localEulerAngles.y >= 180f) {
transform.Rotate(Vector3.up, tiltSpeed);
light.transform.Rotate(Vector3.up, tiltSpeed);
rotating = true;
yield return new WaitForSeconds(0.01f);
}
if (transform.localEulerAngles.y == 0) {
rotating = false;
}
}
}
It likes to output values like 40.00001 and 180.001.
Should I just go ahead and run some code to truncate these digits, or is there some underlying issue I should be aware of?
I am running Unity version 5.6.2f1.