using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace XiaoYu
{
public class MouseEnterEffect : MonoBehaviour
{
[SerializeField, Header("控制鼠标显示")]
bool isOver;
[SerializeField]
private Camera _camera;
private Vector3 screenV; //屏幕坐标
[SerializeField]
GameObject t;
private void Start()
{
_camera = Camera.main;
//世界坐标转换为屏幕坐标
screenV = _camera.WorldToScreenPoint(t.transform.position);
}
private void Update()
{
if (isOver)
{
Vector3 dianV = Input.mousePosition; //鼠标点击位置
dianV.z = screenV.z;
Vector3 wv = _camera.ScreenToWorldPoint(dianV); 屏幕坐标转换为世界坐标
t.transform.position =new Vector3(wv.x,Mathf.Clamp(wv.y,transform.position.y+2.0f, wv.y), wv.z);
}
}
private void OnMouseOver()
{
t.SetActive(true);
isOver = true;
}
private void OnMouseExit()
{
isOver = false;
t.SetActive(false);
}
}
}