Search Unity

Animation on click of target...

Discussion in 'Animation' started by skaidrojumi, Mar 3, 2019.

  1. skaidrojumi

    skaidrojumi

    Joined:
    Nov 12, 2018
    Posts:
    3
    I'm making a game using cards. When the player clicks the card, the card moves to the camera so it can be easily read. I want it to zoom in on left mouse click, then move back to position when the object is left clicked again.

    I can get it to zoom in, but I can't get it to zoom out properly. Either it just stays put when I click, or it just wraps the animations and plays the over and over (depending on the script I write).

    How can I get this to zoom, pause, and the return after clicked again?

    {
    private Animation playerCardZoom;
    private Animation playerCardZoomout;
    private Animator anim;
    public GameObject playerCard6;
    private bool cardIsDown;
    void Start()
    {
    cardIsDown = true;
    anim = GetComponent<Animator>();
    GetComponent<Animation>();

    }
    private void OnMouseDown()
    {
    if (Input.GetMouseButtonDown(0) && cardIsDown == true)
    {
    anim.SetTrigger("firstClick");
    cardIsDown = false;

    }

    if (Input.GetMouseButtonDown(0) && cardIsDown == false)
    {

    anim.SetTrigger("secondClick");
    cardIsDown = true;

    }
    }
    }
     

    Attached Files:

    Last edited: Mar 6, 2019