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;
}
}
}
}
}