当前位置:网站首页>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
边栏推荐
猜你喜欢

用D435i录制自己的数据集运行ORBslam2并构建稠密点云

test

Bridge between ischemic stroke and intestinal flora: short chain fatty acids

Jetpack 之 LifeCycle 组件使用详解

Go reflection rule

Kotlin. The binary version of its metadata is 1.6.0, expected version is 1.1.15.

AWS EKS 部署要点以及控制台与eksctl创建的差异

How to regulate intestinal flora? Introduction to common natural substances, probiotics and prebiotics

Use recyclerview to realize left-right side-by-side classification selection

Nature medicine reveals individual risk factors of coronary artery disease
随机推荐
383. Ransom letter
A lifetime of needs, team collaboration can play this way on cloud nailing applet
Error occurs when thymeleaf th: value is null
基于英飞凌MCU GTM模块的无刷电机驱动方案开源啦
数据孤岛是什么?为什么2022年仍然存在数据孤岛?
IEEE Transactions on Industrial Informatics(TII)投稿须知
用D435i录制自己的数据集运行ORBslam2并构建稠密点云
New terminal play method: script guidance independent of technology stack
Leetcode005 -- delete duplicate elements in the array in place
Key points of AWS eks deployment and differences between console and eksctl creation
Go 语言中的 logger 和 zap 日志库
Leetcode008 -- implement strstr() function
The 14th issue of HMS core discovery reviews the long article | enjoy the silky clip and release the creativity of the video
/etc/bash_ completion. D directory function (the user logs in and executes the script under the directory immediately)
Redis 命令大全
Last day of 2017
Open the past and let's start over.
Leetcode002 -- inverts the numeric portion of a signed integer
PIP3 installation requests Library - the most complete pit sorting
那些年我面试过的Android开发岗总结(附面试题+答案解析)