Question by
Wesley21spelde · Feb 25, 2016 at 01:38 PM ·
animationprogramming
How to change in to if move
hey guys i have a question aboute the player run animation i have this script but it is not working propperly and i want to change it to if movedirection forward &backward left and right but i dont know how to do that so thats the question
using UnityEngine;
using System.Collections;
public class PlayerUTRAnimations : MonoBehaviour
{
public float minimumRunSpeed = 1;
public float speed = 1;
public GameObject Player; // this is assinged becouse have al mt weapons attached to a box with the animations on it
// Use this for initialization
void Start()
{
GetComponent<Animation>().CrossFade("Idle");
GetComponent<Animation>().wrapMode = WrapMode.Loop;
GetComponent<Animation>()["Idle"].layer = -1;
GetComponent<Animation>()["Run"].layer = -1;
GetComponent<Animation>().Stop();
}
void SetSpeed(float speed)
{
if (speed > minimumRunSpeed)
GetComponent<Animation>().CrossFade("Run");
else
GetComponent<Animation>().CrossFade("Idle");
}
// Update is called once per frame
void Update()
{
if (Input.GetKey("w"))
GetComponent<Animation>().CrossFade("Run");
else
GetComponent<Animation>().CrossFade("Idle");
if (Input.GetKey("s"))
GetComponent<Animation>().CrossFade("Run");//this is later changed to an other animation running backwards
if (Input.GetKey("a"))
GetComponent<Animation>().CrossFade("Run");//this is later changed to an other animation running left
if (Input.GetKey("d"))
GetComponent<Animation>().CrossFade("Run");//this is later changed to an other animation running Right
}
}
Comment
$$anonymous$$ecanim can handle animations with speed. Take a look at BlendTrees.
Your answer
![](https://koobas.hobune.stream/wayback/20220612065555im_/https://answers.unity.com/themes/thub/images/avi.jpg)