一.使用Cinemachine中的FreeLookCamera
这里不过多介绍(这里有详细介绍https://blog.youkuaiyun.com/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键, 鼠标滚轮试试看~~。
本文介绍如何在Unity中使用Cinemachine的FreeLookCamera进行实时策略游戏(RTS)摄像机控制。通过设置InputManager输入控制参数,利用鼠标滚轮实现镜头伸缩,并为FreeLook相机的目标挂载脚本来响应键盘方向输入,实现平滑的摄像机移动。
3150

被折叠的 条评论
为什么被折叠?



