I'm trying to get a card to flip when clicked but the flipping only works the first flip. While debugging, I can see that OnMouse is called every time I click.
public class CardController : MonoBehaviour
{
bool isShowingFront = true;
bool isFlipping = false;
float speed = 0.005F;
Quaternion flipRotation = new Quaternion (0, 0, 0, 0);
// Use this for initialization
void Start ()
{
}
// Update is called once per frame
void Update ()
{
if (transform.rotation.y != flipRotation.y) {
transform.rotation = Quaternion.Lerp (transform.rotation, flipRotation, Time.deltaTime * speed);
isFlipping = true;
} else {
isFlipping = false;
}
}
void OnMouseUp ()
{
if (isShowingFront) {
flipRotation.y = 180;
} else {
flipRotation.y = 0;
}
isShowingFront = !isShowingFront;
Debug.Log ("I was clicked");
}
}
Update()
function clean, and you can store variables in the coroutine instead of having to put them on your class. \$\endgroup\$