1 //ClickMove - - 通过鼠标点击控制物体移动 2 3 using System.Collections; 4 using System.Collections.Generic; 5 using UnityEngine; 6 using UnityEngine.AI; // include NavMeshAgent 7 8 public class ClickMove : MonoBehaviour { 9 10 public NavMeshAgent player;11 12 //获取动画组件13 //public Animator anim;14 15 // Use this for initialization16 void Start () {17 18 }19 20 // Update is called once per frame21 void Update () {22 23 if(Input.GetMouseButtonDown(0))24 {25 //通过鼠标点击的位置生成射线26 Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);27 RaycastHit hit;28 if(Physics.Raycast(ray,out hit))29 {30 print(hit.point);31 player.SetDestination(hit.point); //转递鼠标点击信息32 }33 }34 35 //控制动画的播放36 //anim.SetFloat("Speed", player.velocity.magnitude);37 38 }39 }
ClickMove - - 通过鼠标点击控制物体移动