Advertisement

.SetActive(false); not working

Started by August 03, 2020 04:15 PM
2 comments, last by Juliean 4 years, 3 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

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

Advertisement

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