- Home /
Animator problem start animation
Hello everyone!
When I press the left mouse button on a box collider should animate a second animation. when I press the button I get this cluster error: Invalid Layer Index UnityEngine.Animator: Play (String) $: MoveNext () (at Assets / x ninja / Code / Upload blocking livello.js: 18) UnityEngine.SendMouseEvents: DoSendMouseEvents (Int32, Int32)
What could be the problem?
script:
var levelToLoad : String;
var soundhover : AudioClip;
var beep : AudioClip;
var QuitButton : boolean = false;
var anim : Animator;
function Start()
{
anim = GetComponent("Animator");
}
function OnMouseEnter(){
audio.PlayOneShot(soundhover);
}
function OnMouseDown(){
anim.Play ("Secondo");
audio.PlayOneShot(beep);
yield new WaitForSeconds(15);
if(QuitButton){
Application.Quit();
}
else{
Application.LoadLevel(levelToLoad);
}
}
@script RequireComponent(AudioSource)
Answer by Positive7 · Jul 29, 2015 at 10:54 PM
You can't use OnMouseDown() as Corutine
var levelToLoad : String;
var soundhover : AudioClip;
var beep : AudioClip;
var QuitButton : boolean = false;
var anim : Animator;
function Start()
{
anim = GetComponent("Animator");
}
function OnMouseEnter(){
audio.PlayOneShot(soundhover);
}
function OnMouseDown(){
PlayAnim("Secondo");
}
function PlayAnim(animString : String)
{
anim.Play (animString);
audio.PlayOneShot(beep);
yield new WaitForSeconds(15);
if(QuitButton){
Application.Quit();
}
else{
Application.LoadLevel(levelToLoad);
}
}
@script RequireComponent(AudioSource)
Afaik On$$anonymous$$ouseWhatever() can't handle corutines. but you can call corutine function like I did above. Try the above script if it doesn't work let me know.
I tried your change in the script but does not function. I always get this error: Invalid Layer Index UnityEngine.Animator: Play (String) $: $$anonymous$$oveNext () (at Assets / x ninja / Code / Upload blocking livello.js: 18) UnityEngine.Send$$anonymous$$ouseEvents: DoSend$$anonymous$$ouseEvents (Int32, Int32)
On my test scene it works fine. is it a single anim? you could try to use Animation ins$$anonymous$$d of Animator. I'll try reproducing this error :)
I have 2 animations 1) idle animation. 2) second animation, which has to work when I press the left mouse button.
Your answer
Follow this Question
Related Questions
AnimationEvent has no receiver, but there is no AnimationEvent 1 Answer
Animation not playing? 1 Answer
Different animation on each wayPoint 1 Answer
On Hit play animation 0 Answers
Controls are not cooperating with me all of a sudden. 1 Answer