Space Rob thinking: update 12
- ronchisa
- Nov 9, 2023
- 2 min read
Updated: Jan 10, 2024
Well, making the buttons pop in&out was a puzzle.
Firstly, I tried what's already in place for the Player GameObject when you die (which, I'm sure is rather long-winded and antiquated): make object enabled = false, remove renderer -nope, button ain't got a renderer.
Then, I tried using the animation built-in fade effect...which, I'm sure could work, but ultimately even if I made the button totally transparent and the text invisible, if I clicked where said button was, it would still register such click.
So, I moved to "GameObject.SetActive(false);", which, worked! But, if I then re-set as true immediately after, it's impossible to notice the transition.
Ok, I need a delay...well, the Player dying effect uses a coRoutine for said delay, so I'll copy that -let's say press button, call coRoutine, active is false, wait a second, active is true...nope, doesn't re-set it as true.
Turns out this is not a bug: once you set a GameObject as false, it is literally removed from the scene and from memory, and you cannot re-set it as true, since the script simply cannot locate it (which still puzzles me, for if done without a delay, both false and true setting seemed to work...or, maybe one wasn't checked?).
Well, try as I might to coerce the coRoutine into making this work, it wouldn't: research suggested making the gameObject public, calling it via another script...but hark! There are other ways to cause a delay!
So, now I tried this: Invoke(name of Method, time in seconds), and that does the trick, it lets me...nope, still inactive, although it at least didn't throw a massive wobbly like the CoRoutine, which wouldn't even initiate if the GameObject was inactive...
Ok, I then need to find a way for the GameObject to check whether it is active -which led to the stumbling upon the final piece of the jigsaw! GameObject.activeSelf returns whether the GameObject attached to the script is active, and thusly, if this comes back false, I then ask pwetty pwease with cherries on top for it to be re-activated...and it worked! The buttons now disappear once clicked, and reappear shortly after!
Now, they're a bit glitchy, and they keep popping about within their grid rather than remain stationary, so next stop is to stabilise em up!

Here's the buttons in all their glory, released into the wilds!

And here's a bit of the aforementioned code! typeIndex is associated with the separate button texts -eg. One says "Stop", it's typeIndex is 2.
Yours convolutedly,
Stefano Ronchi
Comments