Hello.
The problem: Whenever I walk into the Trigger and press space, it does what I want. However, if I go back outside the collider, I can still activate it by pressing space. This is not ideal.
I want it to only activiate when I am inside the trigger.
Thank you.
Script (C#):
using System.Collections;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class TheFinale : MonoBehaviour {
public string Footsteps;
public string MouseLook;
public string PlayerMovement;
public GameObject MainCamera;
public GameObject FirstPersonPlayer;
public Animator thefinale;
public Animator animat;
public Animator notasbad;
public Animator therose;
public Animator camanim;
public Animator rainanim;
public Text textthepromise;
public Text messenger;
public RawImage black;
public AudioSource dirtsteps;
public bool InTrigger;
Collider Otha;
// Use this for initialization
void Update()
{
if (InTrigger)
{
if (Otha.gameObject.name == "Shovel")
{
thefinale.SetBool("ThePromiseIN", true);
if (Input.GetKeyDown("space"))
{
(FirstPersonPlayer.GetComponent(Footsteps) as MonoBehaviour).enabled = false;
(FirstPersonPlayer.GetComponent(PlayerMovement) as MonoBehaviour).enabled = false;
(MainCamera.GetComponent(MouseLook) as MonoBehaviour).enabled = false;
therose.SetBool("rosepara", true);
camanim.SetBool("cameraparaAnim", true);
StartCoroutine(Final());
StartCoroutine(Notasbadco());
dirtsteps.Stop();
}
}
}
}
private void OnTriggerEnter(Collider other)
{
Otha = other;
InTrigger = true;
}
private void OnTriggerExit(Collider other)
{
InTrigger = false;
}
IEnumerator Final()
{
yield return new WaitForSeconds(5);
rainanim.SetBool("rainboolOut", true);
animat.SetBool("BlackFadeParaOUT", true);
yield return new WaitUntil(() => textthepromise.color.a == 0 && black.color.a == 1);
yield return new WaitForSeconds(8);
SceneManager.LoadScene(2);
}
IEnumerator Notasbadco()
{
yield return new WaitUntil(() => black.color.a == 1);
notasbad.SetBool("notbadparaIN", true);
}
}