Unityで3dゲームを作っています。
Playerの移動をしようとして、下記のプログラムをプレイヤー(プレハブ)にアタッチしました。
CanvasにImageがあって、それにEvent Triggerがアタッチされています。
そこで、右ボタンを押すと、関数「R」が実行され、左ボタンを押すと関数「L」が実行されます。
実行をして、右ボタン、左ボタンをそれぞれ押すと、アニメーションは再生されるのですが、オブジェクトは動きません。
どうしたらよいのでしょうか?
C#
1using System.Collections; 2using System.Collections.Generic; 3using UnityEngine; 4 5public class Player : MonoBehaviour 6{ 7 8 Animator anim; 9 void Start() 10 { 11 anim = GetComponent<Animator>(); 12 } 13 14 void Update() 15 { 16 17 18 } 19 public void R() 20 { 21 anim.SetFloat("Speed", 1.0f); 22 transform.position += new Vector3(0, 0, 1 * Time.deltaTime); 23 24 } 25 public void L() 26 { 27 anim.SetFloat("Speed", 1.0f); 28 transform.position -= new Vector3(0, 0, 1 * Time.deltaTime); 29 } 30 public void Idle() 31 { 32 anim.SetFloat("Speed", 0.0f); 33 } 34} 35
回答1件
あなたの回答
tips
プレビュー