「Unity5 3D/2Dゲーム開発
作りながら覚えるスマートフォンゲーム制作」という本を買い
それに従ってUnityで簡単なゲームを作成しているのですが
公式サイトから配布されているオブジェクトをUnityに導入し
導入したオブジェクトに本通りのC#スクリプトを書き
適用したところ
なぜか導入したオブジェクトの子として設定した
床(これは自分が本通りに作成)が下に向かって動いてしまいます
本来なら下に向かって動かないはずなのですが
公式サイトに間違いと修正が載っていたのですが
そこには自分が元にしたページは載っていませんでした
エラーにはならず、症状が症状なので調べ方も分からず
ここに至った次第です
バージョン:Unity5.5.4(64bit)
OS:Windows10 Home(64bit)
C#
1using UnityEngine; 2 3using System.Collections; 4 5public class NejikoController : 6//NejikoControllerは導入したオブジェクト 7 8MonoBehaviour { 9 CharacterController controller; 10 11Animator animator; 12 13Vector3 moveDirection = Vector3.zero; 14 15 16public float gravity; 17 18public float speedZ; 19 20public float speedJump; 21 22 23 // Use this for initialization 24 25 26void Start () { 27 28 29controller = GetComponent<CharacterController> (); 30 31 32animator = GetComponent<Animator> (); 33 34 35 36} 37 38 // Update is called once per frame 39 40 41void Update () { 42 43 44 45if(controller.isGrounded) { 46 47 48if(Input.GetAxis("Vertical") > 0.0f) { 49 50 51moveDirection.z = Input.GetAxis("Vertical") * speedZ; 52 53 54 } 55 56 57 58else { 59 60 61moveDirection.z = 0; 62} 63 64 65transform.Rotate (0, Input.GetAxis ("Horizontal") * 3, 0); 66 67 68 69if(Input.GetButton("Jump")) { 70 71 72moveDirection.y = speedJump; 73 74 75animator.SetTrigger ("jump"); 76 77 78} 79 80 81 82} 83 84 85 86moveDirection.y -= gravity * Time.deltaTime; 87 88 89 90Vector3 globalDirection = transform.TransformDirection(moveDirection); 91 92 93controller.Move(globalDirection * Time.deltaTime); 94 95 96 97if(controller.isGrounded) 98 99moveDirection.y = 0; 100 101 102 103animator.SetBool("run",moveDirection.z > 0.0f); 104 105 106} 107 108 109 110}
回答1件
あなたの回答
tips
プレビュー