- Home /
stop triggers from retriggering animation
how do i stop animation/audio from retriggering after i have triggered it, thank you
function OnTriggerEnter (player : Collider){
if (player.tag=="Player")
GameObject.Find("woodchair").animation.Play("flyingchair");
GameObject.Find("woodchair1").animation.Play("flyingchair2");
GameObject.Find("stairsong").audio.Play();
}
Answer by YasanthaPrabath · Dec 16, 2013 at 11:42 AM
Class ABC
{
bool IsPlaying = false;
function OnTriggerEnter (player : Collider)
{
if (player.tag=="Player" && IsPlaying == false)
{
IsPlaying = true;
GameObject.Find("woodchair").animation.Play("flyingchair");
GameObject.Find("woodchair1").animation.Play("flyingchair2");
GameObject.Find("stairsong").audio.Play();
}
}
It's mixed javascript and C#.
try:
var IsPlaying = false;
i managed to solve it with
collider.enabled = false;
but i get a nullreferenceexception but it does not stop the game from playing. does it matter about that?
Answer by swredcam · May 22, 2020 at 07:35 PM
I was able to correct a similar issue by disabling "Can Transition to Self", on the transition into my animation clip in the Animator. Clip on the transition arrow and you will find this setting in the "settings" section on the inspector.
Your answer
Follow this Question
Related Questions
Trying to play other objects' sound and animations from Raycast hit 1 Answer
Play Animation OnTriggerEnter 2 Answers
activate audio / animation on trigger 2 Answers
Synchronize Audio and Animation 0 Answers
Triggering an animation via distance 1 Answer