I have an object (a simple card) equipped with the Rigidbody, Collider and Animator components. In particular, Animator performs two simple clips: Cover and Uncover that rotates the card 180 degrees. The first starting from 0 degrees to 180, the second from 180 to 0.
So the clips should cover or uncover the card. The problem is that the card returns to its original state.
For example, the original state of the card is the "uncovered state" so when I click on it to cover it covers as expected. The I register the state "covered" programmatically. However, immediately after the animation ends, it returns to its original state (uncovered). The card now has an internal (C# variable) state as "covered", but I see it to still be uncovered. When I click it again, will be fired the correct animation clip: "uncover".
What should I do to leave it covered at the first click?
I have uploaded here a short clip that shows the behavior of the card, also below find some screenshots that refer to the various views of the IDE that may have useful information. The video clip is uploaded to Dropbox for the while.
The video of the behavior: Dropbox link
The code of the Flip script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Flip : MonoBehaviour {
private Animator anim;
private enum cs_e {covered, uncovered};
private cs_e coveringState;
// Use this for initialization
void Start () {
anim = this.GetComponent<Animator>();
coveringState = cs_e.uncovered;
}
// Update is called once per frame
void Update () {
}
private void OnMouseUp()
{
Debug.Log("Mouse up");
if (coveringState == cs_e.uncovered)
{
anim.Play("Cover");
coveringState = cs_e.covered;
} else {
anim.Play("Uncover");
coveringState = cs_e.uncovered;
}
}
private void OnMouseDown()
{
Debug.Log("Mouse down");
}
private void MouseDrag()
{
Debug.Log("Mouse drag");
}
}
Some screenshots: