unity点击拖拽Cube模型旋转,Cube模型的鼠标点击,抬起等事件

在这里插入图片描述using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.EventSystems;
public class MouseRotate : MonoBehaviour {

public Vector3 mousepos;

// Use this for initialization
void Start () {
	
}

// Update is called once per frame
void Update () {
	
}
/// <summary>
/// 点击拖拽Cube模型旋转
/// </summary>
private IEnumerator OnMouseDown()
{
    mousepos = Input.mousePosition;
    while(Input.GetMouseButton(0))
    {
        Vector3 offset = mousepos - Input.mousePosition;
        transform.Rotate(Vector3.up * offset.x, Space.World);
       // transform.Rotate(Vector3.left * offset.y, Space.World);
        mousepos = Input.mousePosition;
        yield return null;
    }
}
/// <summary>
/// 按住
/// </summary>
private void OnMouseDrag()
{
    //Debug.Log("按住");
}
/// <summary>
/// 鼠标进入
/// </summary>
private void OnMouseExit()
{
    //Debug.Log("鼠标进入");
}
/// <summary>
/// 鼠标离开
/// </summary>
private void OnMouseEnter()
{
    //Debug.Log("鼠标离开");
}
/// <summary>
/// 松开时
/// </summary>
private void OnMouseUp()
{
    //Debug.Log("松开时");
}
/// <summary>
/// 在同一目标抬起
/// </summary>
private void OnMouseUpAsButton()
{
    //Debug.Log("在同一目标抬起");
}
/// <summary>
/// 在同一目标停留时
/// </summary>
private void OnMouseOver()
{
    //Debug.Log("在同一目标停留时");
}

}

发布了24 篇原创文章 · 获赞 3 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/qiao2037641855/article/details/105441699