M
M
madmaga2021-02-12 14:29:20
Unity
madmaga, 2021-02-12 14:29:20

Unity how to create animation on touch?

I want that when I touch my character, the animation will play
and then the original animation will return. (which was before the touch)
in my case, click 1 is the initial animation of the character (when I do nothing)
and click 2 is the animation when the mouse is clicked or touched.
I need the
original click 1 animation to return after the click 2 animation.
When I click or touch, the click 2 animation is played and weighs on this click 2 infinitely.
For example, in the Talking Tom application,
when we touch Tom's head or stomach,
a hit animation is played,
and after that Tom returns to its original state.
And when I touch the character once
, this is the hit animation
reproduced endlessly

tried such a script. Created an int variable in the animator

public class toches : MonoBehaviour
{
Animator animtoches;

private void OnMouseDown()
{
if(Input.touchCount == 0)
{
animtoches.SetInteger("click", 1);
}
else if (Input.touchCount >0)
{
animtoches.SetInteger("click",2);
}

void Start()
{
animtoches = GetComponent Animator();
}


I tried to write the same script in void upade.
but the desired result was not achieved

who can help with the script.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question