Unity3D編程學習 小知識_人物移動導航_2018Oct
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
public class PlayerMove : MonoBehaviour {
public GameObject myObj;
void Start () {
}
void Update () {
if (Input.GetMouseButtonUp (0)) {
Ray myRay = Camera.main.ScreenPointToRay (Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast (myRay, out hit)) {
if (hit.collider.gameObject.tag == "box") {
Debug.DrawLine (myRay.origin, hit.point, Color.red);
myObj.GetComponent<NavMeshAgent> ().SetDestination (hit.point);
myObj.GetComponent<NavMeshAgent> ().speed = 5;
myObj.GetComponent<NavMeshAgent> ().acceleration = 8;
myObj.GetComponent<NavMeshAgent> ().angularSpeed = 100;
}
}
}
}
}
Unity3D編程學習 小知識_人物移動導航_2018Oct