unity2020使用Cinemachine是实现相机上下左右移动

2022-07-29,

一.使用Cinemachine中的FreeLookCamera

这里不过多介绍(这里有详细介绍https://blog.csdn.net/js0907/article/details/108396431)

二.设置InputManager输入控制参数: 在projectSetting中设置

三鼠标滚轮实现镜头伸缩

四.给FreeLook相机的 FollowTarget目标挂个脚本:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class RTSCameraMove : MonoBehaviour
{
    public Transform follwCube;
    public float speed = 10;
    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        var hor = Input.GetAxis("Horizontal");
        var ver = Input.GetAxis("Vertical");
        follwCube.position += new Vector3(hor, 0, ver) * (speed * Time.deltaTime);
    }
}

运行unity,在场景中新建一个cube作为参照物,按下adws键, 鼠标滚轮试试看~~。

本文地址:https://blog.csdn.net/js0907/article/details/108557704

《unity2020使用Cinemachine是实现相机上下左右移动.doc》

下载本文的Word格式文档,以方便收藏与打印。