'Toggle panel with "space" input key
Good morning everyone. I must finish a little project for next month in unity. This project is a remestered Angry Bird. I want to create a code which allow to display and hide a panel everytime when I use Space touch on my keyboard. Here's my code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class RadialMenu : MonoBehaviour
{
public GameObject[] RadialMenuItems;
public AudioSource AudSourc;
public AudioClip MovementClip;
public AudioClip UseClip;
public GameObject radialMenu;
Vector2 NormalizedMPose;
float AngleOfMouse;
int SelectedItem;
int PrevItemID=5;
void Update()
{
if ((radialMenu.activeSelf == true) && Input.GetKey("space"))
radialMenu.SetActive(false);
else if((radialMenu.activeSelf == false) && Input.GetKey("space"))
radialMenu.SetActive(true);
}
}
But it doesn't work. I can hide the panel when I click in Space button for the first time but I can't display it again with the button. I'm actually stuck on it and I can't finish my project. Any help please Thanks
Solution 1:[1]
If the GameObject is disabled the Update method is not executed executed anymore.
A solution would be to disable a child GameObject, so that the Update method is executed.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | JeanLuc |
