Question by
mik-s · Jun 03, 2020 at 09:52 PM ·
gameobjectsetactivegetkeydown
How to make a gameObject appear when I press spacebar down?
public GameObject mercurio;
void Update()
{
mercurio.SetActive(false);
if (Input.GetKeyDown(KeyCode.Space))
mercurio.SetActive(true);
}
Comment
Answer by KoenigX3 · Jun 04, 2020 at 07:43 AM
Remove the 5th line: mercurio.SetActive(false).
Your code is fine otherwise, but since you were inactivating the object on every frame, you could only activate the GameObject for 1 frame with the spacebar.
Edit: If you want your GameObject to start with an inactive state, use the 5th line in void Start, or set the GameObject to inactive in the Inspector.
Your answer
![](https://koobas.hobune.stream/wayback/20220613000020im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Raycasting + setActive() 1 Answer
Game Over panel do not setactive true when collide with enemy, Why ? Please help! 0 Answers
Trigger Sets GameObject 0 Answers
GameObject SetActive not reactivating 5 Answers