前提・実現したいこと
初めまして。Unityを触り始めたばかりの初心者です。
ちょっと行き詰ってしまったので質問させて頂きたいと思います。
CrossPlatformInputManagerを用いて、キャラクター(player)の移動を行わせたいと思っているのですが思うように動作してくれません。
(UIのジョイスティックを操作することで、入力状態の時にplayerが動くようにしてたい)
Standard AssetにあるJoystick.csを用いているのですが、UIとなる画像はオリジナルで作ったものを使っています(UI:MoveStick_over)。
Joystick.csをMoveStick_overにアタッチし、新たに作成したMoveMobile.csをplayerにアタッチしております。
Joystick.cs内のコードは特に変更はしておりません。
以上となります。
宜しくお願い致します。
該当のソースコード(MoveMobile.cs)
C#
1using System.Collections; 2using System.Collections.Generic; 3using UnityEngine; 4using UnityStandardAssets.CrossPlatformInput; 5using UnityEngine.AI; 6 7public class MoveMobile : MonoBehaviour 8{ 9 10 NavMeshAgent agent = null; 11 12 void Awake() 13 { 14 agent = GetComponent<NavMeshAgent>(); 15 } 16 17 // Update is called once per frame 18 void Update() 19 { 20 // 入力を取得 21 var v1 = CrossPlatformInputManager.GetAxis("Vertical"); 22 var h1 = CrossPlatformInputManager.GetAxis("Horizontal"); 23 24 // スティックが倒れていれば、移動 25 if (h1 != 0 || v1 != 0) 26 { 27 var direction = new Vector3(h1, 0, v1); 28 agent.Move(direction * Time.deltaTime); 29 } 30 } 31}
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/01/08 05:12