using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
public class ModelShow : MonoBehaviour
{
public int RotationSpeed= 1;
Vector3 MouseBegin;
Vector3 MouseEnd;
bool IsRotation = true;
bool IsUI =true;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if (Input.GetMouseButtonDown(0))
{
MouseBegin = Input.mousePosition;
IsUI = EventSystem.current.IsPointerOverGameObject();
}
if (Input.GetMouseButton(0)&&!IsUI)
{
IsRotation = false;
MouseEnd = Input.mousePosition;
float Distance = Vector3.Distance(MouseBegin, MouseEnd);
if (Distance != 0)
{
IsRotation = false;
transform.Rotate(new Vector3(0, (MouseBegin - MouseEnd).normalized.x * Distance*0.3f, 0));
MouseBegin = MouseEnd;
}
}
if (Input.GetMouseButtonUp(0))
{
IsRotation = true;
}
if (transform.childCount != 0 && IsRotation)
{
transform.Rotate(new Vector3(0, RotationSpeed, 0));
}
}
}
做的是一个物体在什么时候触发鼠标点击旋转功能
if (EventSystem.current.IsPointerOverGameObject() == false)
{
//没有在UI上面
}
else
{
//点击在UI上面
}
以布尔值方式返回 与UI接口不冲突