Question by
PLEBUSORIS · Sep 22, 2016 at 04:47 AM ·
animation2d2d game2d animation
Animation Script on GetKeyPressed
I have been working on a 2d game for about two weeks now. I am stuck on my animation script where if you press a key you would move forward and have the move forward animation play. This game I am working on is an RPG like game, so there is no jump but rather X and Y movement.
Here is my script so far:`
Animator anim;
// Use this for initialization
void Start () {
anim = GetComponent<Animator>();
}
// Update is called once per frame
void Update () {
}
public void WalkN(){
if(Input.GetKeyDown(KeyCode.W)){
anim.SetBool ("WalkN", true);
}
if(Input.GetKeyDown(KeyCode.S)){
anim.SetBool ("WalkS", true);
}
if(Input.GetKeyDown(KeyCode.D)){
anim.SetBool ("WalkE", true);
}
if(Input.GetKeyDown(KeyCode.A)){
anim.SetBool ("WalkW", true);
}
if(Input.GetKeyUp(KeyCode.W)){
anim.SetBool ("WalkN", false);
}
if(Input.GetKeyUp(KeyCode.A)){
anim.SetBool ("WalkW", false);
}
if(Input.GetKeyUp(KeyCode.S)){
anim.SetBool ("WalkS", false);
}
if(Input.GetKeyUp(KeyCode.D)){
anim.SetBool ("WalkE", false);
}
}`
Comment
Please edit your question! Your script didn't make it into the post. ;)
Your answer
Follow this Question
Related Questions
Problem with Jump Animation 0 Answers
How do I stop an animation from looping? 1 Answer
Animation location problem! 0 Answers
Script to animation and movement of 2d player 1 Answer
2d object moves only a little then stops 0 Answers