- Home /
Animation loop noob Problem
Hello Right now im trying to use this. this is the script that is just receiving everything
var targetHand: GameObject; var Up: MouseEnterUp; var Down : MouseEnterDown; var ContA : int = 0; var ContB : int = 0;
function Start(){ targetHand= GameObject.Find("As_Hand"); Up= GameObject.Find("CubeUp").GetComponent(MouseEnterUp); Abajo = GameObject.Find("CubeDown").GetComponent(MouseEnterDown); } function Update() { if(Up.EnterA == true) { ContA = 1; } if(Down.EnterB == true) { ContB = 1; }
if((ContA == 1) && (ContB == 1)) { targetHand.animation.wrapMode = WrapMode.PingPong; targetHand.animation.Play("Clean"); // name of the animation clip ContA=0; ContB=0; } }
this is the code that calls EnterA this is another script EnterB is the same thing except that the var is named EnterB and the script is also named different but thats about it
var wasClicked : boolean; var EnterA: boolean = false; function Update() { if(Input.GetButtonDown("Fire1")) { wasClicked=true; } else if(Input.GetButtonUp("Fire1")) { wasClicked=false; Deactivate(); } }
function OnMouseEnter() { if (wasClicked) { Activate(); } }
function OnMouseExit() { Deactivate(); }
function Activate() { EnterA = true; }
function Deactivate() { EnterA =false; }
The animation is playing at first when A and B are both 1 then it loops infinitely any ideas? thank you very much
Need to see more, what is setting Up.EnterA and Up.EnterB. Unless you set them to false it's just going to go back into the animation loop.
Answer by zannghast · Feb 02, 2011 at 01:18 AM
This may be the cause (or start of it):
targetHand.animation.wrapMode = WrapMode.PingPong;
With PingPong, the animation doesn't really automatically stop. So unless you explicitly tell it to, the animation won't stop. It would just 'ping pong' back and forth between its beginning and end.
yeah that is a good start i tried with wrapmode.once but the problem now is if mouse enters either up or down it plays the animation ins$$anonymous$$d of checking for both :S
i think im going with this for now i would hope that ping pong could be used that way ins$$anonymous$$d of an infinite loop >.< oh well thank you very much that was very helpful
Did you want the animation to play just once and depending on whether the mouse is 'up' or 'down'?
Answer by hypnoslave · Feb 02, 2011 at 01:20 AM
woah woah woah! surely this is unnecessary. you've got 2 scripts to look for buttonUp and buttonDown events and flag a boolean variable? Surely you dont need that. What are you trying to do?
It looks like you're just trying to play an animation when the user holds down 2 buttons?
Unless I don't understand something that you're trying to accomplish, you should be able to just use this and only this (frankly, this is probably already a little sloppy):
var hasPlayed : boolean = false; var targetHand= GameObject.Find("As_Hand");
function Update()
{
if(Input.GetButton(x) && Input.GetButton(y) && !hasPlayed)
{
hasPlayed = true;
targetHand.animation.wrapMode = WrapMode.PingPong;
targetHand.animation.Play("Clean"); // name of the animation clip
}
if((Input.GetButtonUp(x) || Input.GetButtonUp(y)) && hasPlayed)
{
hasPlayed = false;
targetHand.animation.Stop();
}
}
seems like a good answer im off to try it ty and btw im not trying to get input buttons im trying to check if mouse is entering an object and if it enters top then bottom object then play animation and thats about it :S
the animation Stop wont work cuz its making it not play the whole animation just like 3 frames or so :S
Your answer
![](https://koobas.hobune.stream/wayback/20220613102348im_/https://answers.unity.com/themes/thub/images/avi.jpg)