- Home /
Activate one object, others appear, with GUI
For my 2D platformer in unity 4.6, I was wondering how to open a chest when a player comes into contact with it and presses a button, and from the chest it launches a few collectables out. Also how would I show those collectables that came out of the chest, when the player comes into contact with them, as GUI popups on the screen?
I was just wondering what the easiest way to approach this is as I don't have a large knowledge on this type of thing while using C#
Answer by Landern · Jun 02, 2015 at 01:14 PM
You'll have to keep a variable to indicate whether the chest is opened.
Using Rigidbody2d and colliders you would implement OnTriggerStay2d along with a check for the desired Input GetButtonDown. Play the animation of the chest opening(if that is something you want to display) along with the items popping out. Using OnTriggerEnter2D, show the items on screen, OnTriggerExit2D to stop showing them in the UI.