Home > other >  Can a Unity UI button move or destroy itself on press
Can a Unity UI button move or destroy itself on press

Time:10-30

enter image description here

I'm trying to start my game with none of the systems in place and the only thing on the screen is some background objects and the BUTTON.

when I press the button, I want to instantiate all the objects that I need in the game.(which i know how to do, and isnt my problem.)

MY PROBLEM is that i want the button to either

  1. destroy itself or 2) Move off screen or 3) scale down so it cant be seen.

the script i have in place should be doing the scale down solution as thats attached to the onpress function but nothing seems to happen to the button on press but it does seem to manipulate the prefab of the button that isnt even on screen?

CAN A BUTTON NOT MANIPULATE ITSELF?

CodePudding user response:

I think you need to refactor your code as it doesnt look good. But if you just want to make your button work then try to use button.transform.localScale instead of getting RectTransform component.

CodePudding user response:

I would suggest you just simply deactivate the button instead of messing with the scale or destroying it.

You can use the following code to hide your button

gameObject.SetActive(false);
  • gameObject is the current object that the script is attached to it

If you have a refference of your button component you can use the bellow code

button.gameObject.SetActive(false);
  • Related