🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

.SetActive(false); not working

Started by
2 comments, last by Juliean 3 years, 11 months ago

hello, i'm trying to build a simple UI script where when the player presses E the dialogue menu comes up and when he presses esc the dialogue menu disappears. im trying to do so by using SetActive. pressing e sets it as active (true) while escape does nothing, and the canvas remains on the screen. any help?

i dno't have any other script that references this game object at all, so i don't understand what's wrong

public class WomanNPC : MonoBehaviour
{
    private GameObject triggeringPlayer;
    private bool triggering = false;
    public GameObject dialogueBox;
    //public string name = womanNPC;



    // Start is called before the first frame update
    void Start()
    {

    }

    // Update is called once per frame
    void Update()
    {
        if (triggering)
        {
            if (Input.GetKey("e"))
            {
                //this works
                dialogueBox.SetActive(true);
				if (Input.GetKey(KeyCode.Escape))
				{
                    //this does not
                    dialogueBox.SetActive(false);
                }

            }
        }
    }

None

Advertisement

of course. i put the if statment of the setactive false outside of the other if statement and it works now, obviously. keeping this thread if anybody needs it

None

You are checking “Input.GetKey(KeyCode.Escape)" inside the “Input.GetKey(”e")"-condition, so it would only turn off if you pressed both e+ECS at the same time.

Edit: NVM, you found it yourself +1

This topic is closed to new replies.

Advertisement