using System.Collections; using System.Collections.Generic; using Unity.VisualScripting; using UnityEngine; using DG.Tweening; public class TestPenInteractive : MonoBehaviour { public bool isInteractive; public GameObject g1; public bool isDian; private void Update() { if(Input.GetMouseButton(0)) { //1.参数ray 为射线碰撞检测的光线(返回一个从相机到屏幕鼠标位置的光线) Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit, 50)) //如果碰撞检测到物体 { if (hit.collider.transform.tag.Equals("YanDian")) { Debug.Log(hit.collider.name); transform.parent = hit.collider.transform; transform.position = new Vector3(hit.point.x, hit.point.y, hit.point.z+0.5f); } } } else { transform.parent = GameManager.ins.Player.transform; } } }