using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Rendering;
public class FinalCinematic : MonoBehaviour
{
private bool movingPlayer = false;
private bool doOnce = false;
private float path;
private Vector3 A;
private Vector3 B;
private Vector3 C;
private Vector3 D;
private Vector3 E;
private GameObject player;
private Vector3 FirstLocation;
public Vector3 SecondLocation;
public GameObject ThirdLocation;
public GameObject EndLocation;
public GameObject EnemyBase;
public VolumeProfile profile;
public float speed;
private Camera cam;
private GameManager gameManagerRef;
private float score = 0;
private void Start()
{
cam = GetComponentInChildren<Camera>();
gameManagerRef = GameManager.GetInstance();
gameManagerRef.GetComponent<ObjectiveManager>().scoreDropOff += IncreaseScore;
}
private void Update()
{
if (movingPlayer)
{
A = Vector3.Lerp(FirstLocation,SecondLocation,path);
B = Vector3.Lerp(SecondLocation,ThirdLocation.transform.position,path);
C = Vector3.Lerp(ThirdLocation.transform.position,EndLocation.transform.position,path);
D = Vector3.Lerp(A,B,path);
E = Vector3.Lerp(B,C,path);
player.transform.position = Vector3.Lerp(D,E,path);
if (path < 0.9f)
{
player.transform.rotation = Quaternion.LookRotation(Vector3.Lerp(D, E, (path + 0.01f)) - player.transform.position);
}
if (path > 1)
{
gameManagerRef.SetState((int)State.Win);
}
path += 0.15f * Time.deltaTime;
}
}
private void IncreaseScore()
{
score++;
if (score == 5)
{
player = gameManagerRef.PlayerRef;
FirstLocation = player.gameObject.transform.position;
SecondLocation = player.transform.position + player.gameObject.transform.forward * 50f;
player = player.gameObject;
player.GetComponent<FlyBehaviour>().enabled = false;
player.GetComponent<HealthBehaviour>().SetImmortal();
movingPlayer = true;
doOnce = true;
cam.enabled = true;
Camera.main.enabled = false;
profile.components[6].active = false;
EnemyBase.GetComponent<FinalExplosion>().BlowUpTower();
gameManagerRef.CanavasManagerRef.ToggleCutsceneMode(false);
}
}
private void OnTriggerEnter(Collider other)
{
if (other.tag == "Player" && doOnce == false)
{
print(other.gameObject.name);
FirstLocation = other.gameObject.transform.position;
SecondLocation = other.transform.position + other.gameObject.transform.forward * 50f;
player = other.gameObject;
player.GetComponent<FlyBehaviour>().enabled = false;
player.GetComponent<HealthBehaviour>().SetImmortal();
movingPlayer = true;
doOnce = true;
cam.enabled = true;
Camera.main.enabled = false;
profile.components[6].active = false;
EnemyBase.GetComponent<FinalExplosion>().BlowUpTower();
gameManagerRef.CanavasManagerRef.ToggleCutsceneMode(false);
}
}
}