using UnityEngine; using System.Collections;
public class PlayerCtrl : MonoBehaviour { [System.Serializable] //요걸 적어줘야 자바스크립트로 짠게 씨샵에서 된다. public class Anims { public AnimationClip idle; public AnimationClip runForward; public AnimationClip runBackward; public AnimationClip runLeft; public AnimationClip runRight; } public Anims anims; public Animation anybody; public float Speed = 10.0f; // Use this for initialization void Start () { anybody.clip = anims.idle; //anybody.clip = anims.runForward; anybody.Play(); } // Update is called once per frame void Update () { float v = Input.GetAxis("Vertical"); float h = Input.GetAxis ("Horizontal"); transform.Translate(Vector3.forward * v * Time.deltaTime * Speed); transform.Translate(Vector3.right * h * Time.deltaTime * Speed); if(v > 0.1f) { // 동작을 혼합시켜 주는 함수 크로스페이드 anybody.CrossFade(anims.runForward.name,0.3f); } else if(v < -0.1f){ anybody.CrossFade(anims.runBackward.name,0.3f); } else if(h < -0.1f){ anybody.CrossFade(anims.runLeft.name,0.3f); } else if(h > 0.1f){ anybody.CrossFade(anims.runRight.name,0.3f); }else anybody.CrossFade(anims.idle.name,0.3f); } }
|