using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class SwitchCameras : MonoBehaviour
{
[Header("Cameras Init")]
public Camera[] cameras;
public Vector3[] originalPosition;
[Space(5)]
[Header("Cameras Switch")]
public string currentCameraName;
public Vector3[] lastCameraPosition;
public float cameraSpeed;
[Space(5)]
[Header("Cameras Target")]
public float nextTargetDistance;
public Vector3 nextTargetPosition;
public Transform nextTarget;
private int currentCamera = 0;
void Start()
{
cameras = Camera.allCameras;
lastCameraPosition = new Vector3[cameras.Length];
if (cameras.Length >= 1)
{
originalPosition = new Vector3[cameras.Length];
for (int i = 0; i < cameras.Length; i++)
{
originalPosition[i] = cameras[i].transform.position;
}
}
if (cameras.Length == 1)
{
Debug.LogError("Need more then 1 camera for switching..");
}
else
{
Debug.Log("Found " + cameras.Length + " cameras");
}
for (int i = 0; i < cameras.Length; i++)
{
cameras[i].enabled = false;
}
cameras[0].enabled = true;
currentCameraName = cameras[0].name;
}
void LateUpdate()
{
if (Input.GetKeyDown(KeyCode.C))
{
cameras[currentCamera].enabled = false;
if (++currentCamera == cameras.Length)
currentCamera = 0;
cameras[currentCamera % cameras.Length].enabled = true;
cameraSpeed = (cameras[currentCamera].transform.position - lastCameraPosition[currentCamera]).magnitude / Time.deltaTime;
lastCameraPosition[currentCamera] = cameras[currentCamera].transform.position;
currentCameraName = cameras[currentCamera].name;
Debug.Log(cameras[currentCamera].name + " Last position " + cameras[currentCamera].transform.position);
}
}
}
Two things i want to do:
When running the game display the movement speed of cameras[0] in the Update i want to see the speed in real time not only once like still.
Then when i click on C to switch between the cameras display each camera in real time the movement speed. Now when i click on C and switch between the cameras i see still speed value and not real time running value of the speed.
Debug.Log
until you change the camera? The question is a little unclear but that might just be me not understanding the problem. \$\endgroup\$Debug.Log
statement. Is this script on a camera or an empty gameobject? \$\endgroup\$