当前位置:网站首页>Unity攝像頭跟隨鼠標旋轉
Unity攝像頭跟隨鼠標旋轉
2022-04-23 04:41:00 【龍胖胖的博客】
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()
{
//攝像頭移動
//float x = Input.GetAxis("Horizontal") * Time.deltaTime * 5;
//float y = Input.GetAxis("Vertical") * Time.deltaTime * 5;
//transform.Translate(x, 0, y);
//限制攝像頭移動的範圍
//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);
//點擊鼠標右鍵旋轉攝像頭
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);
}
}
}
版权声明
本文为[龍胖胖的博客]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230441112442.html
边栏推荐
- 383. 赎金信
- unity摄像机旋转带有滑动效果(自转)
- leetcode004--罗马数字转整数
- Small volume Schottky diode compatible with nsr20f30nxt5g
- 华为机试--高精度整数加法
- MySQL queries users logged in for at least N consecutive days
- Bridge between ischemic stroke and intestinal flora: short chain fatty acids
- 递归调用--排列的穷举
- Practice and exploration of knowledge map visualization technology in meituan
- Unity RawImage背景无缝连接移动
猜你喜欢

Installation of zynq platform cross compiler

229. Find mode II

IDE idea automatic compilation and configuration of on update action and on frame deactivation

阿里十年技术专家联合打造“最新”Jetpack Compose项目实战演练(附Demo)

AWS EKS 部署要点以及控制台与eksctl创建的差异
![[timing] empirical evaluation of general convolution and cyclic networks for sequence modeling based on TCN](/img/c5/3b3f9cf9a39bf14a68ac100294ca6c.png)
[timing] empirical evaluation of general convolution and cyclic networks for sequence modeling based on TCN

Interaction of diet gut microbiota on cardiovascular disease

MYSQL50道基础练习题

zynq平臺交叉編譯器的安裝

补充番外14:cmake实践项目笔记(未完待续4/22)
随机推荐
在AWS控制台创建VPC(无图版)
MYSQL去重方法汇总
Chlamydia infection -- causes, symptoms, treatment and Prevention
Installation and deployment of Flink and wordcount test
test
[pytoch foundation] torch Split() usage
Record your own dataset with d435i, run orbslam2 and build a dense point cloud
FAQ of foreign lead and alliance Manager
Supplement: Annotation
The last day of 2021 is the year of harvest.
Record the blind injection script
Migrate from MySQL database to AWS dynamodb
520. Detect capital letters
The perfect combination of collaborative process and multi process
Youqilin 22.04 lts version officially released | ukui 3.1 opens a new experience
Unity RawImage背景无缝连接移动
Iron and intestinal flora
IEEE Transactions on Systems, Man, and Cybernetics: Systems(TSMC)投稿须知
用D435i录制自己的数据集运行ORBslam2并构建稠密点云
QML进阶(四)-绘制自定义控件