相机的统一运动?



所以我和我的朋友们正在Unity 中选择一个相机,我们想添加一个凸轮"跟随",所以我们在这里和那里编辑了一个 youtube 教程以满足我们的目的。但是当我们运行它时,我们遇到了一个问题,相机不会移动到汽车上,它只是停留在我们放置的地方。任何人都可以帮忙。用 c# 编码

法典:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Camswitch : MonoBehaviour{
public GameObject cam1;
public GameObject cam2;
public GameObject cam3;
public GameObject follow;
public Transform target;
public float smoothSpeed = 0.125f;
void LateUpdate ()
{
transform.position = target.position;
}
void Update(){
if (Input.GetButtonDown("1key"))
{
cam1.SetActive(true);
cam2.SetActive(false);
cam3.SetActive(false);
follow.SetActive(false);
}
if (Input.GetButtonDown("2key"))
{
cam1.SetActive(false);
cam2.SetActive(true);
cam3.SetActive(false);
follow.SetActive(false);
}
if (Input.GetButtonDown("3key"))
{
cam1.SetActive(false);
cam2.SetActive(false);
cam3.SetActive(true);
follow.SetActive(false);
}
if (Input.GetButtonDown("4key"))
{
cam1.SetActive(false);
cam2.SetActive(false);
cam3.SetActive(false);
follow.SetActive(true);


}
}
}

欢迎来到堆栈溢出。这里的问题似乎是,您从未真正告诉摄像机跟随任何其他游戏对象。您告诉摄像机始终转到设置为您在检查器中放置的任何 Vector3 坐标target.position

我对脚本所做的是编辑目标位置并将其设置为您的一台摄像机的位置。您可以相应地更改它。

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Camswitch : MonoBehaviour{
public GameObject cam1;
public GameObject cam2;
public GameObject cam3;
public GameObject follow;
public Transform target;
public float smoothSpeed = 0.125f;
void LateUpdate ()
{
target.transform.position = cam1.transform.position; //Change this to whatever camera you want it to follow.
transform.position = target.position;
}
void Update(){
if (Input.GetButtonDown("1key"))
{
cam1.SetActive(true);
cam2.SetActive(false);
cam3.SetActive(false);
follow.SetActive(false);
}
if (Input.GetButtonDown("2key"))
{
cam1.SetActive(false);
cam2.SetActive(true);
cam3.SetActive(false);
follow.SetActive(false);
}
if (Input.GetButtonDown("3key"))
{
cam1.SetActive(false);
cam2.SetActive(false);
cam3.SetActive(true);
follow.SetActive(false);
}
if (Input.GetButtonDown("4key"))
{
cam1.SetActive(false);
cam2.SetActive(false);
cam3.SetActive(false);
follow.SetActive(true);


}
}
}

最新更新