using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class OpenningScene : MonoBehaviour
{
[Header("Animators")]
public Animator[] animators;
[Space(5)]
[Header("Movement Settings")]
public Transform target;
public float movingSpeed = 1f;
public bool slowDown = false;
[Space(5)]
[Header("Rotation Settings")]
public float rotationSpeed;
public DepthOfField dephOfField;
public float waitingAnimation;
public float startConversation;
[Space(5)]
[Header("Cameras")]
public Camera cameras;
private Vector3 targetCenter;
private bool startWaitingAnim = true;
private bool endRot = false;
private int medea_m_arrebola_index;
private List<int> soldiers_indexs;
// Use this for initialization
void Start()
{
targetCenter = target.GetComponent<Renderer>().bounds.center;
soldiers_indexs = new List<int>();
for (int i = 0; i < animators.Length; i++)
{
animators[i].SetFloat("Walking Speed", movingSpeed);
if(animators[i].name == "medea_m_arrebola")
{
medea_m_arrebola_index = i;
}
else
{
soldiers_indexs.Add(i);
}
}
}
// Update is called once per frame
void Update()
{
if (dephOfField.dephOfFieldFinished == true)
{
PlayConversations.PlaySingleConversation(0);
dephOfField.dephOfFieldFinished = false;
}
float distanceFromTarget = Vector3.Distance(animators[medea_m_arrebola_index].transform.position, target.position);
if (slowDown)
{
if (distanceFromTarget < 10)
{
float speed = (distanceFromTarget / 10);
for (int i = 0; i < animators.Length; i++)
{
animators[i].SetFloat("Walking Speed", speed);
}
}
}
if (distanceFromTarget < 5f)
{
for (int i = 0; i < animators.Length; i++)
{
animators[i].SetBool("Idle", true);
if (startWaitingAnim == true)
{
StartCoroutine(WaitForAnimation());
startWaitingAnim = false;
}
}
if (waitinganimation == true)
{
animators[medea_m_arrebola_index].SetBool("Magic Pack", true);
waitinganimation = false;
PlayConversations.PlaySingleConversation(1);
}
if(distanceFromTarget > 10 && BeginningCutsceneTrigger.entered == true)
{
}
for (int i = 0; i < soldiers_indexs.Count; i++)
{
animators[soldiers_indexs[i]].SetBool("Rifle Aiming Idle", true);
if (!endRot)
{
Quaternion goalRotation = Quaternion.Euler(0f, 0f, 0f);
float angleToGoal = Quaternion.Angle(
goalRotation,
animators[soldiers_indexs[i]].transform.localRotation);
float angleThisFrame = Mathf.Min(angleToGoal, rotationSpeed * Time.deltaTime);
int index = soldiers_indexs[i];
animators[index].transform.Rotate(index % 2 == 0 ? Vector3.up : Vector3.down, angleThisFrame);
// We end if we rotated the remaining amount.
endRot = (angleThisFrame == angleToGoal);
}
}
}
}
bool waitinganimation = false;
IEnumerator WaitForAnimation()
{
yield return new WaitForSeconds(waitingAnimation);
waitinganimation = true;
}
private void SwitchCameras()
{
}
}
I have two cameras in this case one of them is enabled true the other one is disabled.
The one that is disabled is the Main Camera.
I want at some place/time to switch between the cameras using the SwitchCameras method.
At this place in the script I want to switch between the cameras. The current working camera should be disabled and the Main Camera(Or the second camera could be just another camera not main) should b enabled true :
if(distanceFromTarget > 10 && BeginningCutsceneTrigger.entered == true)
{
}
I could make it like this :
if(distanceFromTarget > 10 && BeginningCutsceneTrigger.entered == true)
{
cameras[0].enabled = false;
cameras[1].enabled = true;
}
But let’s say the current working camera is not at index 0 ? Maybe it’s in index 1 ? In this case I have two cameras and I know that the one at index 0 will be the current one but if I have 10 cameras and I’m getting the cameras like this :
cameras = FindObjectsOfType<Camera>();
Then how do I know what camera is the active one now ?
Not sure if Camera.current is the right way to find the current active camera.