26行目(Camera.main.transform.forward, new Vector3...)でエラーが起きています。
インスタンスのセットの仕方がわかりません。どうしたらよいでしょうか。
今急ぎで作らなければならないため、Vector3など、使い方がわからないまま本に書いてあることを入力しているだけなのでC#やUnityに関する知識の浅さはどうかご容赦下さい。
public class Animation : UnityEngine.MonoBehaviour { private Animator animator; private const string isRun = "isRun"; private const string isJump = "isJump"; private float movement = 20f; private float moveX = 0f; private float moveZ = 0f; void Start () { this.animator = GetComponent<Animator>(); } void Update() { var cameraForward = Vector3.Scale( Camera.main.transform.forward, new Vector3(1, 0, 1) ).normalized; var vertial = cameraForward * Input.GetAxis("Vertial"); var horizontal = Camera.main.transform.right * Input. GetAxis("Horizontal"); var direction = vertial + horizontal; moveX = direction.x * Time.deltaTime * movement; moveZ = direction.z * Time.deltaTime * movement; transform.Translate(moveX, 0f, moveZ, Space.World); if (moveX != 0 || moveZ != 0) { transform.rotation = Quaternion.LookRotation(direction); this.animator.SetBool(isRun, true); } else { this.animator.SetBool(isRun, false); } if (Input.GetKey(KeyCode.Space)) { this.animator.SetBool(isJump, true); } else { this.animator.SetBool(isJump, false); } } }
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/09/23 11:15