Created
February 9, 2015 18:57
-
-
Save CosmoCleaner/9472193f3b458de7a878 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using UnitySampleAssets.CrossPlatformInput; | |
/// <summary> | |
/// バーチャルジョイスティックでNavMeshAgentを操作 | |
/// NavMeshAgent にアタッチして使用 | |
/// </summary> | |
public class AgentControlledByJoystick : MonoBehaviour { | |
/// <summary> | |
/// 目的地表示用マーカー | |
/// </summary> | |
public Transform destinationMarker; | |
NavMeshAgent agent; | |
void Awake() | |
{ | |
agent = GetComponent<NavMeshAgent>(); | |
} | |
void Update() | |
{ | |
float x = CrossPlatformInputManager.GetAxisRaw ("Horizontal"); | |
float z = CrossPlatformInputManager.GetAxisRaw ("Vertical"); | |
Vector3 destinationPos = transform.position + new Vector3(x, 0, z); | |
agent.SetDestination(destinationPos); | |
if (destinationMarker) | |
{ | |
destinationMarker.position = destinationPos; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment