Unity使用鼠标旋转物体效果
作者:PangCoder 时间:2021-10-17 05:08:12
本文实例为大家分享了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.点击运行,按下鼠标左键拖动即可
来源:https://blog.csdn.net/qq_36251561/article/details/111210078
标签:unity,鼠标,旋转
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
java仿windows记事本小程序
2023-11-25 09:24:43
Redis分布式锁实现方式及超时问题解决
2023-08-24 23:28:34
C语言字符串另类用法的实现
2023-06-19 02:05:25
ConcurrentHashMap是如何实现线程安全的你知道吗
2023-11-28 23:14:25
![](https://img.aspxhome.com/file/2023/5/60195_0s.jpg)
详解Java设计模式之备忘录模式的使用
2023-09-10 09:38:32
![](https://img.aspxhome.com/file/2023/7/58437_0s.jpg)
spring boot springMVC扩展配置实现解析
2023-11-25 10:32:53
Java中自动装箱、拆箱引起的耗时详解
2023-01-11 11:42:42
java compare compareTo方法区别详解
2022-06-26 08:13:55
java8 实现提取集合对象的每个属性
2023-10-17 19:37:27
Java 你知道什么是耦合、如何解(降低)耦合
2022-03-23 08:44:19
Spring整合junit的配置过程图解
2022-12-18 16:37:48
![](https://img.aspxhome.com/file/2023/5/66975_0s.png)
Spring Boot 入门教程
2023-05-26 00:14:44
Java金额大小写的转换方法
2023-08-23 00:26:11
java二维数组遍历的2种代码
2022-05-03 08:52:50
![](https://img.aspxhome.com/file/2023/7/63997_0s.png)
JAVA实现对阿里云DNS的解析管理
2023-11-24 13:25:15
Java程序员面试中的多线程问题总结
2021-12-12 07:48:33
intellij idea中spring boot properties文件不能自动提示问题解决
2021-09-24 09:53:46
![](https://img.aspxhome.com/file/2023/2/62442_0s.png)
使用javaMail实现发送邮件
2023-01-20 21:22:26
![](https://img.aspxhome.com/file/2023/1/64121_0s.jpg)
你知道将Bean交给Spring容器管理有几种方式(推荐)
2021-07-17 08:36:23
![](https://img.aspxhome.com/file/2023/7/63447_0s.png)
Java面向对象之抽象类,接口的那些事
2022-08-25 19:16:30
![](https://img.aspxhome.com/file/2023/0/61530_0s.jpg)