86 lines
2.7 KiB
C#
86 lines
2.7 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"))
|
|
{
|
|
transform.parent = hit.collider.transform;
|
|
transform.position = hit.point;
|
|
if (hit.transform.GetComponent<door_control>())
|
|
{
|
|
list.Add(hit.transform.GetComponent<door_control>());
|
|
FractionManager.Instance.isYanDian = true;
|
|
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.Instance.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;
|
|
}
|
|
|
|
}
|
|
private void OnDestroy()
|
|
{
|
|
if (UIManager.Instance)
|
|
{
|
|
if (GameManager.Instance.YanDian)
|
|
{
|
|
GameManager.Instance.interactiveEnum = Interactive.none;
|
|
}
|
|
else
|
|
{
|
|
GameManager.Instance.interactiveEnum = Interactive.YanDianOk;
|
|
}
|
|
}
|
|
Debug.Log("埃里克及时反馈辣椒水:" + GameManager.Instance.interactiveEnum);
|
|
}
|
|
}
|