unityでゲームを作っているのですがプレイヤーを動かすためにCharacter ControllerのScriptを書いたのですがエラーも起きなければ動きもしません。
プログラムに問題があるのか、それともunity上での操作が悪いのか知りたいので
このソースに問題があるか見て頂けないでしょうか。よろしくお願いします
WalkとIdelはアニメーション名です。
lang
1 2using UnityEngine; 3using System.Collections; 4 5public class PlayerController : MonoBehaviour { 6 7 float walkspeed = 3.0f; 8 float gravity =20.0f; 9 private Vector3 velocity; 10 11 12 // Use this for initialization 13 void Start () { 14 animation ["Walk"].speed = 2.0f; 15 16 17 } 18 19 // Update is called once per frame 20 void Update () { 21 CharacterController controller = GetComponent<CharacterController>(); 22 23 if(controller.isGrounded){ 24 25 Vector3 velocity = new Vector3(Input.GetAxis("Horizontal"),0.0f,Input.GetAxis("Vertical")); 26 velocity *= walkspeed; 27 28 if(velocity.magnitude > 0.5){ 29 animation.CrossFade("Walk", 0.1f); 30 transform.LookAt(transform.position + velocity); 31 }else{ 32 animation.CrossFade("Idel", 0.1f); 33 } 34 velocity.y -= gravity * Time.deltaTime; 35 36 controller.Move(velocity * Time.deltaTime); 37 } 38 39 } 40}
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。