【发布时间】:2021-01-12 01:43:13
【问题描述】:
我想在按下按钮时将主摄像机从一个点缓慢移动到另一个点。此按钮调用具有移动相机代码的方法。
我曾尝试使用 Lerp 方法,但摄像机位置变化太快,以至于当我单击按钮时摄像机直接移动到新位置。我想让相机慢慢移动到一个新的位置。
下面是我的代码,谁能帮帮我。
================================================ ============================
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Cameramove : MonoBehaviour
{
public GameObject cam;
Vector3 moveToPosition;// This is where the camera will move after the start
float speed = 2f; // this is the speed at which the camera moves
public void move()
{
//Assigning new position to moveTOPosition
moveToPosition = new Vector3(200f, 400f, -220f);
float step = speed * Time.deltaTime;
cam.transform.position = Vector3.Lerp(cam.transform.position, moveToPosition, step);
cam.transform.position = moveToPosition;
}
}
【问题讨论】: