54 lines
1.8 KiB
C#
54 lines
1.8 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.EventSystems;
|
|
|
|
public class MultimeterManager : MonoBehaviour
|
|
{
|
|
public Transform blackXian;
|
|
public Transform RedXian;
|
|
private Multimeter multimeter;
|
|
public Camera Camera;
|
|
public List<Multimeter> Multimeter;
|
|
// Start is called before the first frame update
|
|
void Start()
|
|
{
|
|
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
if (Camera)
|
|
{
|
|
// 鼠标左键按下
|
|
if (Input.GetMouseButtonDown(0))
|
|
{
|
|
// 从相机位置发射一条射线经过屏幕上的鼠标点击位置
|
|
Ray ray = Camera.ScreenPointToRay(Input.mousePosition);
|
|
// 声明一个射线碰撞信息类
|
|
RaycastHit hit;
|
|
// 进行碰撞检测
|
|
bool res = Physics.Raycast(ray, out hit,50, 1 << 7) && !EventSystem.current.IsPointerOverGameObject();
|
|
if (res)
|
|
{
|
|
// 如果产生了碰撞
|
|
if (hit.collider.name.Equals("RedWanYon"))
|
|
{
|
|
//GameManager.Instance.BlackWanYon = null;
|
|
GameManager.Instance.RedWanYon = RedXian.gameObject;
|
|
//GameManager.Instance.RedWanYonPos = GameManager.Instance.RedWanYon.transform.localPosition;
|
|
}
|
|
if (hit.collider.name.Equals("BlackWanYon"))
|
|
{
|
|
//GameManager.Instance.RedWanYon = null;
|
|
GameManager.Instance.BlackWanYon = blackXian.gameObject;
|
|
//GameManager.Instance.BlackWanYonPos = GameManager.Instance.BlackWanYon.transform.localPosition;
|
|
}
|
|
Debug.Log(hit.collider.name);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|