Hello. I made a button on canvas(not prefab) and using it for a 2d platformer. For an example, if the player(2d) is colliding with the ladder, a button will pop up. Once the button is pushed, the player starts to climb the ladder. If the player is not touching the ladder, the button will go away. Any way that can be done?
Sure. Detect when the player touches the ladder, display button. When they aren’t, remove the button. Since it’s 2d and a ladder, you probably want to look at the 2d colliders and setting it to trigger at the ladder and use OnTriggerEnter and OnTriggerExit to determine when you should display the button.
That makes sense, but I can’t figure out how to make the button appear by scripting
There are a lot of ways, but the most direct way is that a button is a Gameobject as well. Button is just a component. So if you have a reference to the button Gameobject, you can just use SetActive(true/false) to turn it on or off.
Pretty much what you said. But does that go with buttons and images?
Not really sure what you mean by with buttons and images, but if it’s in your scene, it’s a gameobject. So SetActive works on it. buttons and images are just components. While you can enable and disable components as well, that may not be the best option, just depending on the results you want.
Generally speaking, setting the gameobject active or not is probably easier to understand while you’re learning.