当前位置:网站首页>The unity camera rotates with the mouse
The unity camera rotates with the mouse
2022-04-23 04:41:00 【Longpangpang's blog】
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraMove : MonoBehaviour {
float _rotationX;
float rotationY;
public float sensitivityHor = 5.0f;
public float sensitivityVert = 5.0f;
public float minimumVert = -45.0f;
public float maximumVert = 45.0f;
// Update is called once per frame
void Update()
{
// The camera moves
//float x = Input.GetAxis("Horizontal") * Time.deltaTime * 5;
//float y = Input.GetAxis("Vertical") * Time.deltaTime * 5;
//transform.Translate(x, 0, y);
// Limit the range of camera movement
//float move_x = Mathf.Clamp(transform.position.x, -20f, 20f);
//float move_y = Mathf.Clamp(transform.position.y, -20f, 20f);
//float move_z = Mathf.Clamp(transform.position.z, -20f, 20f);
//transform.position = new Vector3(move_x, move_y, move_z);
// Click the right mouse button to rotate the camera
if (Input.GetMouseButton(1))
{
rotationY = transform.localEulerAngles.y + Input.GetAxis("Mouse X") * sensitivityHor;
_rotationX -= Input.GetAxis("Mouse Y") * sensitivityVert;
_rotationX = Mathf.Clamp(_rotationX, minimumVert, maximumVert);
transform.localEulerAngles = new Vector3(_rotationX, rotationY, 0);
}
}
}
版权声明
本文为[Longpangpang's blog]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230441112442.html
边栏推荐
- Mysql50 basic exercises
- Luogu p1858 [multi person knapsack] (knapsack seeking the top k optimal solution)
- 针对NFT的网络钓鱼
- SQL statement for adding columns in MySQL table
- 2020 is coming to an end, special and unforgettable.
- 递归调用--排列的穷举
- 电钻、电锤、电镐的区别
- Bacterial infection and antibiotic use
- 协程与多进程的完美结合
- Unity RawImage背景无缝连接移动
猜你喜欢
那些年我面试过的Android开发岗总结(附面试题+答案解析)
Go reflection rule
Bridge between ischemic stroke and intestinal flora: short chain fatty acids
简单的拖拽物体到物品栏
[timing] empirical evaluation of general convolution and cyclic networks for sequence modeling based on TCN
Recommended scheme for national production of electronic components of wireless keyboard
Small volume Schottky diode compatible with nsr20f30nxt5g
zynq平台交叉编译器的安装
Shanghai Hangxin technology sharing 𞓜 overview of safety characteristics of acm32 MCU
A new method for evaluating the quality of metagenome assembly - magista
随机推荐
Record the blind injection script
Iron and intestinal flora
Bridge between ischemic stroke and intestinal flora: short chain fatty acids
重剑无锋,大巧不工
Effects of antibiotics on microbiome and human health
Go reflection - go language Bible learning notes
Use recyclerview to realize left-right side-by-side classification selection
Improving 3D object detection with channel wise transformer
SQL statement for adding columns in MySQL table
Programmers complain: I really can't live with a salary of 12000. Netizen: how can I say 3000
leetcode008--实现strStr()函数
基于英飞凌MCU GTM模块的无刷电机驱动方案开源啦
Gut liver axis: host microbiota interaction affects hepatocarcinogenesis
Go反射—Go语言圣经学习笔记
leetcode007--判断字符串中的括号是否匹配
Code007 -- determine whether the string in parentheses matches
Leetcode003 -- judge whether an integer is a palindrome number
Installation and use of Apache bench (AB pressure test tool)
win10, mysql-8.0.26-winx64. Zip installation
補:注解(Annotation)