- Home /
OnTriggerStay not working correctly.
Hello.
I have a script where i want bool parameter "BlackFadeParaOUT" to activate the moment my character has entered trigger collider "Shovel" and spacebar has been pressed. But my problem is that sometimes when i enter the trigger collider, the parameter activates without me pressing my Spacebar. How do i fix this?
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 musicAnim;
public Text textayy;
// Use this for initialization
void Start()
{
GetComponent<AudioSource>();
}
private void OnTriggerStay(Collider other)
{
if (other.gameObject.name == "Shovel")
{
thefinale.SetBool("ThePromiseIN", true);
if (Input.GetKeyDown("space"))
{
animat.SetBool("BlackFadeParaOUT", true);
musicAnim.SetTrigger("RainFadeTrigger");
StartCoroutine(Final());
StartCoroutine(promisefinale1());
(MainCamera.GetComponent(MouseLook) as MonoBehaviour).enabled = false;
(FirstPersonPlayer.GetComponent(PlayerMovement) as MonoBehaviour).enabled = false;
(FirstPersonPlayer.GetComponent(Footsteps) as MonoBehaviour).enabled = false;
}
}
}
private void FixedUpdate()
{
if (Input.GetKeyDown("escape"))
{
Cursor.lockState = CursorLockMode.None;
}
if (Input.GetMouseButton(0))
{
Cursor.lockState = CursorLockMode.Locked;
}
}
private void OnTriggerExit(Collider other)
{
StartCoroutine(promisefinale2());
}
IEnumerator Final()
{
yield return new WaitForSecondsRealtime(10);
SceneManager.LoadScene(2);
}
IEnumerator promisefinale1()
{
yield return new WaitUntil(() => textayy.color.a == 1);
thefinale.SetBool("ThePromiseOUT", true);
}
IEnumerator promisefinale2()
{
yield return new WaitForSeconds(1);
yield return new WaitUntil(() => textayy.color.a == 1);
thefinale.SetBool("ThePromiseOUT", true);
}
}
Some notes that might be useful to know:
My character has no rigidbody, and uses the Character Controller.
Gameobject "Shovel" has a child, but it has no other components attached to it.
If there are more things you want to know, make sure to ask and i'll give you the necessary information.
Thank you in advance. :)
I also want to mention that i've already tried changing it to if (other.gameObject.name == "Shovel" && Input.GetKeyDown("space"))
, but this sadly gives the same effect.