Skip to content

Instantly share code, notes, and snippets.

@CosmoCleaner
Created February 9, 2015 18:57
Show Gist options
  • Save CosmoCleaner/9472193f3b458de7a878 to your computer and use it in GitHub Desktop.
Save CosmoCleaner/9472193f3b458de7a878 to your computer and use it in GitHub Desktop.
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