C#
1 using UnityEngine; 2using System.Collections; 3 4public class PolisController : MonoBehaviour 5{ 6 7 CharacterController controller; 8 Animator animator; 9 10 Vector3 moveDirection = Vector3.zero; // 移動方向計算用 11 float gravity = 9.8f; // 重力 12 float speedZ = 3.0f; // 進行方向の速度 13 14 // Use this for initialization 15 void Start() 16 { 17 18 // 必要なコンポーネントを取得 19 controller = GetComponent<CharacterController>(); 20 animator = GetComponent<Animator>(); 21 } 22 23 // Update is called once per frame 24 void Update() 25 { 26 27 // Inputを検知して前に進める 28 if (Input.GetAxis("Vertical") > 0.0f) 29 { 30 moveDirection.z = Input.GetAxis("Vertical") * speedZ; 31 } 32 else 33 { 34 moveDirection.z = 0; 35 } 36 37 // 方向転換 38 transform.Rotate(0, Input.GetAxis("Horizontal") * 3, 0); 39 40 // 重力分の力を毎フレーム追加 41 moveDirection.y -= gravity * Time.deltaTime; 42 43 44 // 移動実行 45 Vector3 globalDirection = transform.TransformDirection(moveDirection); 46 controller.Move(globalDirection * Time.deltaTime); 47 48 // 移動後接地していたらY方向の速度はリセット 49 if (controller.isGrounded) moveDirection.y = 0.0f; 50 51 52 // 速度が0以上なら歩きフラグをtrueにする 53 animator.SetBool("walkFlag", moveDirection.z > 0.0f); 54 55 } 56}
walkFlagというbool型のフラグを作り、上記のコードを書いたのですがtrueになりません。
解決方法が分かる方、ご教授願います。
walkFlagをAnimatorでtrueにした後プレイすればアニメーションの再生はできているので、そこは問題ないです。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/12/19 12:49
2017/12/19 13:17