M
M
madmaga2021-02-24 20:17:30
Unity
madmaga, 2021-02-24 20:17:30

Unity how to disable animation on click or touch?

Hello! I have an "Idle" animation and an "Idle" audio file and I use the "OnMouseDown" method which on click or touch on the collider activates the "toucherglass" animation and the "voiceglas" audio file. I need the animation and audio file "Idle" to be turned off when "OnMouseDown" because unity does not know which animation and audio file to start and pause. (At least it seems to me that this is the reason) Is it possible to write something in "OnMouseDown" then type - playerANimator.Stop("Idle") _audioSource.Stop(Idle) and turn off the desired animation and sound?
Script I am using

public class touchglasses : MonoBehaviour
{
    Animator _playerAnimator;
    AudioSource _audioSource;
    public AudioClip voiceglas;

    private void OnMouseDown()
    {

        _playerAnimator.Play("toucherglass");

        _audioSource.PlayOneShot(voiceglas);
        


        void Start()
        {
            _playerAnimator = GetComponent<Animator>();
            _audioSource = GetComponent<AudioSource>();
        }

       
      


    }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
Black Basher, 2021-02-27
@BlackBasher

In the animator, create a condition and exit on it or switch to another animation, the AudioSource is stopped by the Stop() method

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question