Unity学习笔记1 锁定摄像机镜头跟随角色移动

您所在的位置:网站首页 unity摄像头快捷键 Unity学习笔记1 锁定摄像机镜头跟随角色移动

Unity学习笔记1 锁定摄像机镜头跟随角色移动

2024-07-07 05:10| 来源: 网络整理| 查看: 265

注释:方法非原创,纯笔记,欢迎转载。

准备:1.摄像机 Camera  2.新建C#Script 命名CameraMove

开始:

1.输入:

using System.Collections;using System.Collections.Generic;using UnityEngine;public class CameraMove : MonoBehaviour { public Transform playerTransform; public float smoothing; private Vector3 offset; void Awake(){ offset = transform.position - playerTransform.position; } void FixedUpdate(){ Vector3 newCameraPos = playerTransform.position + offset; transform.position = Vector3.Lerp (transform.position, newCameraPos, smoothing * Time.deltaTime); }

}

2.保存,把文件拖到摄像机Camera上;

3.在Scene窗口中选择合适视角,选中摄像机Camera后按住Ctrl+Shift+F移动摄像机到当前视角(也可以手动调整摄像机位置);

4.摄像机Camera属性,把需要锁定视角移动的角色拖入到Player Transform中,Smoothing后面数字输入5;

5.运行即可。



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3