- Home /
2D 'Run' n 'Jump' Animation question??
hi i am trying to make 2D side-scroller game where my character(4 leg animal) just running and jumping(signal & double) so basically my question is i have one png file in that includes 4 frame for running & 8 frame for jumping so how can i define in the script that when i pressed space then use the jump frames and hide the run fames and when i land on the ground then start again my running frames
basically running is automatically no need to control just one key control space to jump and double space to double jump .
any idea how to do that in unity Thanks
Answer by RoughDesign · Sep 23, 2011 at 06:08 PM
If you want to know how to make something happen when you press keys,
you should have a look at Input.GetAxis or Input.GetButton.
For changing the texture, you can use
var jumpAnimation1 : Texture;
renderer.material.mainTexture = jumpAnimation1;
Don't forget to assign a texture to the script in the inspector before running it.
For using images for several animation states which are stored in 1 texture file ('texture atlas'), there's a way to do it by changing offset and scale of your texture. described here.
Your answer
Follow this Question
Related Questions
Drag and jump mechanics? 2 Answers
My player wont jump (2d game) 1 Answer
How Do I Create Random Platforms in a 2d Game? 0 Answers
I Can't Jump, And If I Remove if(isGrounded) I Can Do More Then 10 Jumps IN The Air 1 Answer
Unity 2D Top Down Jump 1 Answer