Answer the question
In order to leave comments, you need to log in
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
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 questionAsk a Question
731 491 924 answers to any question