45 lines
1.4 KiB
C#
45 lines
1.4 KiB
C#
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;
|
|
List<door_control> list = new List<door_control>();
|
|
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);
|
|
list.Add(hit.transform.GetComponent<door_control>());
|
|
hit.transform.GetComponent<door_control>().启用交互 = false;
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
transform.parent = GameManager.ins.Player.transform;
|
|
}
|
|
}
|
|
private void OnDisable()
|
|
{
|
|
for (int i = 0; i < list.Count; i++)
|
|
{
|
|
list[i].启用交互 = true;
|
|
}
|
|
}
|
|
}
|