using System.Collections;
public class Player : MonoBehaviour {
public NavMeshAgent agent;
Vector3 point;
Ray aray;
RaycastHit ahit;
public GameObject targetPoint;
void Start()
{
targetPoint.active=false;
}
void Update ()
{
if(Input.GetMouseButtonDown (0))
{
aray=Camera.main.ScreenPointToRay(Input.mousePosition);
if(Physics.Raycast(aray,out ahit))
{
point=ahit.point;
//Instantiate(targetPoint,point,transform.rotation);
targetPoint.active=true;
targetPoint.transform.position=point;
}
}
agent.SetDestination(point);
}
}
C#實現U3D簡單尋路
繼續學習c#。。
簡單的尋路,用的是U3D自帶的算法,代碼如下
和之前的相機跟隨一塊的效果
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.