- Home /
Animation Not Playing - VideoExplanation
Hello everyone, Im trying to play an animation by pressing a button. Heres a video of I made the animation.
So, basically you see how it's not playing even though Its running the command and how I made the animation. What am I missing? Yes, I've checked if the animation is legacy....
Thank you for your time.
////EDIT I don't like to put a whole lot of code but If you want to review it, I greatly appreciate it! This is the script attached to the gui, it enables the button for the DPad.
public class DirectionPad : MonoBehaviour {
bool _downPressed;
Animation playerTempANim;
GUISkin mySkin;
// Use this for initialization
void Start () {
mySkin = GetComponent<newGUI>().mySkin;
_downPressed = false;
}
// Update is called once per frame
void Update () {
}
void FixedUpdate(){
if(_downPressed)
PlayAnimation();
}
void OnGUI(){
GUI.skin = mySkin;
if(GUI.RepeatButton(new Rect(Screen.width - (75 * 2) - 10, Screen.height - 75, 65, 65),"", "Dpad_ArrowD")){
// Debug.Log ("Pressing");
_downPressed = true;
}else {
// Debug.Log ("not Pressing");
_downPressed = false;
}
}
void PlayAnimation(){
if(playerTempANim == null)
playerTempANim = GameObject.Find("testAnimation").GetComponent<Animation>();
playerTempANim.Play("WalkDown");
Debug.Log ("Playing " + playerTempANim.animation);
}
}
Since you missed to post all the code parts where you're calling PlayTempAnimation() then make sure that you're not stopping it elsewhere.
Answer by wesleywh · Dec 19, 2014 at 07:48 PM
So go to the animation and change the WrapMode to Loop. Otherwise it might be playing the animation once. This looks like a walk animation so you definitely want to loop that.
Also I noticed that you are doing this in your "Update()" function. That could also be another problem. A better thing to do is check for a button press on "FixedUpdate()".
Also make sure playerTempAnim in your code knows what Animation component to look at. I didn't see anything telling what playerTempAnim was.
EDIT: I also notice you never tell it to run this animation on a button press of any kind, just in the update. Make sure to tell it to run this on you press some button. Otherwise it could cause jitter or keep looping the first second of the animation.
@wesleywh Thank you very much for your time and help! So, I changed Update() to Fixed Update. Nothing. Switched wrap mode from default to Loop.Nothing. I know its not best practice but I made a if statement...if 'anim' is null, find it, else play walk animation, just to make sure its doing it I made a debug just when the animation plays, its "Playing" and you can see that in the debugger when I press the button...so......I really don't know what Im missing here.
Could you include your code for me to review? Its very difficult for me to figure out what might be going on here without your commented code here.
What part of the code exactly? I tried to show in the video how I created a gameObject with animation component from scratch. Either way, I'll add parts of the code as an edit of the question. Thank you for your time Wesley.
After watching the video again I notice that u create e animation with one sprite then try to apply it to another one by the look of it. Is this what you are doing or am I missing something here? Your code looks okay to me and the debug log indicates that its working. However, in the debug log, of the video, it says playing but not what it's playing like your code says. So the two things to check are that you are making the animation for a specific sprite, and not using that animation on something else, and that your are na$$anonymous$$g your animation the same in your code as well as the inspector.
So in your new updated comment you say that you checked to make sure that you weren't running legacy animation.
"Animation" component = Legacy
"Animator" component = is not legacy
In your video you use the "Animation" component which is legacy. So is that different now? Btw you did look at my previous comment? Did that help you at all?
Your answer
Follow this Question
Related Questions
Jump & Animation Script 2D 0 Answers
Animation not at correct position W/Video 0 Answers
Reverse object position order 1 Answer
Animator - Stoping && Playing from Specific frames. 5 Answers
Play an animation through script 0 Answers