• 用Unity实现鼠标旋转效果


    本文为大家分享了Unity使用鼠标旋转物体效果的具体代码,供大家参考,具体内容如下

    1.在Main Camera下新建一个Cube

    然后调整一下Cube的位置,把他放置在相机前方

    2.给Cube挂载脚本

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
     
    public class CubeControlScript : MonoBehaviour
    {
        // Start is called before the first frame update
        void Start()
        {
            //隐藏或者显示物体
            //transform.gameObject.SetActive(true);
        }
     
        // Update is called once per frame
        void Update()
        {
            //如果鼠标左键按下
            if (Input.GetMouseButton(0))
            {
                float speed = 2.5f;//旋转跟随速度
                float OffsetX = Input.GetAxis("Mouse X");//获取鼠标x轴的偏移量
                float OffsetY = Input.GetAxis("Mouse Y");//获取鼠标y轴的偏移量
                transform.Rotate(new Vector3(OffsetY, -OffsetX, 0) * speed, Space.World);//旋转物体
            }
        }
    }

    3.点击运行,按下鼠标左键拖动即可

  • 相关阅读:
    侧滑的一个注意
    viewpager+fragment结合
    webview
    动画
    <context:annotation-config> 和 <context:component-scan>的区别
    spring mvc 原理及应用
    HDU
    使用Log4Net将系统日志信息记录到记事本和数据库中
    chromium for android GPU进程结构分析
    【云图】怎样制作全国KTV查询系统?
  • 原文地址:https://www.cnblogs.com/AranNice/p/16325628.html
Copyright © 2020-2023  润新知