Unity实现飞行相机、路径相机、晃动相机、手机触摸旋转模型、鼠标点击模型播放视频

一、飞行相机代码展示:

UpDown需要在如下添加A、D键

96609bc98b814ee89887118190559991.png

using System;
using UnityEngine;

public class FlightCamera : MonoBehaviour
{
    public Transform flyCamera;
    public float translationSpeed = 5f;
    public float runTranslationSpeed = 10f;
    public float rotationSpeed = 100f;
    
    public float rotationMultiplier = 2f; // 控制旋转速度的倍数
    // public float minRotationAngle = -80f; // 最小旋转角度
    // public float maxRotationAngle = 80f; // 最大旋转角度

    private Vector3 posInit;
    private Vector3 rotInit;
    private Vector3 flyCameraPosInit;
    void Awake()
    {
        posInit = this.transform.position;
        rotInit = this.transform.eulerAngles;
        flyCameraPosInit = flyCamera.transform.localEulerAngles;
    }
    
    public void StartFlyCamera()
    {
        this.transform.position = posInit;
        this.transform.eulerAngles = rotInit;
        flyCamera.transform.localEulerAngles = flyCameraPosInit;
    }
    
    void Update()
    {
        var _translationSpeed = Input.GetKey(KeyCode.LeftShift) ? runTranslationSpeed : translationSpeed;
        
        // 前后移动
        float verticalInput = Input.GetAxis("Vertical");
        transform.Translate(Vector3.forward * verticalInput * _translationSpeed * Time.deltaTime);

        // 上下平移
        float upDownInput = Input.GetAxis("UpDown");
        transform.Translate(Vector3.up * upDownInput * _translationSpeed * Time.deltaTime);

        // 左右旋转
        float horizontalInput = Input.GetAxis("Horizontal");
        transform.Rotate(Vector3.up, horizontalInput * rotationSpeed * Time.deltaTime);
        
        
        // 鼠标右键按下并上下滑动控制 X 轴旋转
        if (Input.GetMouseButton(1))
        {
            float mouseY = Input.GetAxis("Mouse Y") * rotationSpeed * rotationMultiplier * Time.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

平杨猪

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值