using System.Collections; using System.Collections.Generic; using UnityEngine; public class playerControl : MonoBehaviour { private NavMeshAgent agent1; void Start() { } void Update() { //判別按下滑鼠左鍵 if(Input.GetMouseButtonDown(0)) { //射線取得點按位置的坐標 Ray ray1 = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit1; //射線檢測 if(Physics.Raycast(ray1,out hit1)==true) { //取得點擊位置 Vector3 point1 = hit1.point; //觸碰點的物件名稱 = hit1.collider.gameObject.name string name1 = hit1.collider.gameObject.name; } } } }