Quantcast
Channel: Questions in topic: "walk"
Viewing all articles
Browse latest Browse all 88

idle > walk > run animation

$
0
0
Hey i'm making a 2d platformer. I have managed to get my 2d sprite to idle and walk. Now i'm trying to add a run fuction. So, when you press Shift you go faster. This works, how ever the run animation doesn't play? I have the animator set up like this: **idle** (speed > 0.1) **walk** (speed > 4.0) **run** And similar to going back to walking and idle ofcourse. Am i doing this wrong? code: using UnityEngine; using System.Collections; public class PlayerController : MonoBehaviour { public float speed = 4.0f; private Transform myTransform; Animator anim; // Use this for initialization void Start () { myTransform = transform; anim = GetComponent (); } // Update is called once per frame void Update () { //animation anim.SetFloat("speed", Mathf.Abs(Input.GetAxis("Horizontal"))); //move horizontal myTransform.Translate(Vector2.right * Input.GetAxis ("Horizontal") * speed * Time.deltaTime); if(Input.GetKey (KeyCode.LeftShift)) { speed = 8.0f; } else if(!Input.GetKey (KeyCode.LeftShift)){ speed = 4.0f; } } }

Viewing all articles
Browse latest Browse all 88

Trending Articles