大家好,我正在做一个炮弹模式,玩家将拥有一个看起来像狙击屏幕的UI面板 . 这个摄像机将跟随敌人,而在常规游戏中,还有另一个摄像机用于正常播放模式(这个保持在原位) . 然而,当我用“E”退出时,当我在大炮相机移动的任何地方切换时,它都会停留在那个移动的位置 . 有什么方法可以手动将摄像机的位置恢复原位吗?
public class CameraFollow : MonoBehaviour
{
public Transform target;
public float smoothSpeed = 0.125f;
public Vector3 offset;
public GameObject scopeOverlay;
public GameObject Camera;
void FixedUpdate ()
{
if (Input.GetKeyDown ("d"))
{
Camera.SetActive (false);
scopeOverlay.SetActive(true);
Vector3 desiredPosition = target.position + offset;
Vector3 smoothedPosition = Vector3.Lerp (transform.position, desiredPosition, smoothSpeed);
transform.position = smoothedPosition;
transform.LookAt (target);
}
if (Input.GetKeyDown ("e"))
{
Camera.SetActive (true);
scopeOverlay.SetActive(false); //To disable it
}
}
}
1 回答
保存初始变换值并像这样恢复它们;