- Home /
Question by
thetiltedindian · Sep 04, 2018 at 08:50 PM ·
booleanbool
Why is this bool auto turning off?
Hey!
So I'm working on a sniper scope and the bool "Scoped" in my animator tab is automatically turning off and the overlay is still on-screen. Code:
public class Scope : MonoBehaviour {
public Animator animator;
public GameObject scopeOverlay;
public GameObject weaponCamera;
private bool isScoped = false;
void Update()
{
if (Input.GetButtonDown("Fire2"))
{
isScoped = !isScoped;
animator.SetBool("Scoped", isScoped);
if (isScoped)
StartCoroutine(OnScoped());
else
OnUnScoped();
}
}
IEnumerator OnScoped()
{
yield return new WaitForSeconds(.15f);
scopeOverlay.SetActive(true);
weaponCamera.SetActive(false);
}
void OnUnScoped()
{
weaponCamera.SetActive(true);
scopeOverlay.SetActive(false);
}
}
Comment
$$anonymous$$aybe try to StopCoroutine(OnScope); just before you unscopein the else of the update function?
Your answer
Follow this Question
Related Questions
How can i reverse all the booleans in a method? 2 Answers
How would I make 1 bool true whilst making others false 1 Answer
Double collision on "ground" tagged object results in player thinking they're in air? 1 Answer
C# Parameter questions 2D game 1 Answer
Error : Animator has not been initialized. UnityEngine.Animator:SetBool(String, Boolean) 1 Answer