Hey, so for some reason if I run this script and hit E the if statement gets called twice.
void Update () {
Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
if (Physics.Raycast (ray, out hit, 3)){
if (hit.collider.tag == "Item"){
displayGUI = true;
}else{
displayGUI = false;
}
}
}
void OnGUI() {
if(displayGUI){
GUI.Box(new Rect(Screen.width/2 - 100, Screen.height/2 - 12.5f, 200, 25), "Hit E to pick up " + hit.collider.gameObject.GetComponent<Item_Pickup>().name);
if(Input.GetKeyDown(KeyCode.E) && displayGUI) {
Debug.Log("Button is pressed");
}
}
}