您的位置:首页 > 编程语言 > C#

C#实现U3D简单寻路

2017-06-19 20:57 288 查看
继续学习c#。。
简单的寻路,用的是U3D自带的算法,代码如下
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); 
 } 
}
 






和之前的相机跟随一块的效果
因为没有障碍物所以并没有完全体现出寻路的效果
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  3d 3d引擎 实例