Skip to content

Instantly share code, notes, and snippets.

@tarukosu
Created April 23, 2017 08:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tarukosu/7f364bace28448362f5376d84052ece4 to your computer and use it in GitHub Desktop.
Save tarukosu/7f364bace28448362f5376d84052ece4 to your computer and use it in GitHub Desktop.
MoveToClickPoint.cs
using HoloToolkit.Unity.InputModule;
using UnityEngine;
using UnityEngine.AI;
public class MoveToClickPoint : MonoBehaviour, IInputClickHandler
{
public NavMeshAgent Agent;
LineRenderer lineRenderer;
void Start()
{
InputManager.Instance.PushFallbackInputHandler(gameObject);
Agent.gameObject.SetActive(false);
lineRenderer = gameObject.GetComponent<LineRenderer>();
lineRenderer.positionCount = 0;
}
public void OnInputClicked(InputClickedEventData eventData)
{
if (GazeManager.Instance.IsGazingAtObject)
{
var hitInfo = GazeManager.Instance.HitInfo;
if (!Agent.gameObject.activeSelf)
{
Agent.gameObject.SetActive(true);
Agent.transform.position = hitInfo.point;
}
else
{
Agent.destination = hitInfo.point;
// パスの計算
var path = new NavMeshPath();
NavMesh.CalculatePath(Agent.transform.position, Agent.destination, NavMesh.AllAreas, path);
var positions = path.corners;
// ルートの描画
lineRenderer.widthMultiplier = 0.1f;
lineRenderer.positionCount = positions.Length;
for (int i = 0; i < positions.Length; i++)
{
Debug.Log("point " + i + "=" + positions[i]);
lineRenderer.SetPosition(i, positions[i]);
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment