unity:镜头移动代码(通用式)
Posted 肖尘
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了unity:镜头移动代码(通用式)相关的知识,希望对你有一定的参考价值。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class FPMouseLook : MonoBehaviour
private Transform cameraTransform;
[SerializeField]private Transform characterTransform;
private Vector3 cameraRotation;
public float MouseSensitivity;
public Vector2 MaxminAngle;
private void Start()
//获取组件
cameraTransform = transform;
void Update ()
MouseSensitivity = 5;
//鼠标控制
var tmp_MouseX = Input.GetAxis("Mouse X");
var tmp_MouseY = Input.GetAxis("Mouse Y");
//鼠标灵敏度
cameraRotation.x -= tmp_MouseY * MouseSensitivity;
cameraRotation.y += tmp_MouseX * MouseSensitivity;
//限制上下看的范围
cameraRotation.x = Mathf.Clamp(cameraRotation.x,-65,65);
//在世界空间中变换的旋转
cameraTransform.rotation = Quaternion.Euler(cameraRotation.x, cameraRotation.y, 0);
characterTransform.rotation = Quaternion.Euler(0, cameraRotation.y, 0);
以上是关于unity:镜头移动代码(通用式)的主要内容,如果未能解决你的问题,请参考以下文章
Unity: 一个简单的镜头移动/缩放管理类(只移动镜头方式)
unity怎么把一个镜头下的多个脚本一次性复制给另一个镜头?右键弹出的复制功能只能单个复制!