E_ElecCompetition/Electrical_inspectionCompet.../Assets/Script/Interactive/TestPenInteractive.cs

70 lines
2.2 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 Start()
{
if (transform.GetComponent<ToolModelClick>())
{
g1 = transform.GetComponent<ToolModelClick>().Higth;
}
}
private void Update()
{
if (Input.GetMouseButton(0))
{
//1.参数ray 为射线碰撞检测的光线(返回一个从相机到屏幕鼠标位置的光线)
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast(ray, out hit, 100)) //如果碰撞检测到物体
{
if (hit.collider.transform.tag.Equals("YanDian"))
{
Debug.Log(hit.collider.name);
transform.parent = hit.collider.transform;
transform.position = hit.point;
if (hit.transform.GetComponent<door_control>())
{
list.Add(hit.transform.GetComponent<door_control>());
hit.transform.GetComponent<door_control>(). = false;
}
if (hit.transform.GetComponent<TestPenInteractiveSon>())
{
if (hit.transform.GetComponent<TestPenInteractiveSon>().isDian)
{
g1.SetActive(true);
}
else
{
g1.SetActive(false);
}
}
}
}
}
else
{
g1.SetActive(false);
transform.parent = GameManager.ins.Player.transform;
transform.localPosition = new Vector3(0.307f, 0.504f, 0.654f);
transform.localEulerAngles = new Vector3(-180, -180, 180);
}
}
private void OnDisable()
{
for (int i = 0; i < list.Count; i++)
{
list[i]. = true;
}
}
}