Search Unity

How to destroy a UI image by clicking on a Button??

Discussion in 'Editor & General Support' started by carlospicomonte, Jan 18, 2019.

  1. carlospicomonte

    carlospicomonte

    Joined:
    Jan 8, 2019
    Posts:
    11
    Hi, I would like to destroy an image (UI) by pressing a button, too (UI). This is possible?? they passed me a code to destroy sprites, but for my project it would work better with a UI image. Thank you
     
  2. lucernagame

    lucernagame

    Joined:
    Nov 5, 2018
    Posts:
    19
    Can you call the same Object.Destroy referencing the new thing? Such as with Object.Destroy(GameObject.Find("the/full/location"))?
     
    carlospicomonte likes this.
  3. carlospicomonte

    carlospicomonte

    Joined:
    Jan 8, 2019
    Posts:
    11
    gracias. Me has ayudado mucho.
     
  4. MNNoxMortem

    MNNoxMortem

    Joined:
    Sep 11, 2016
    Posts:
    358
    If possible avoid the Find and just drag a reference to from the inspector or set the reference via code. Object.Destroy(image.gameObject) destroys the gameObject while Object.Destroy(image) destroys the component.
     
    carlospicomonte likes this.
  5. carlospicomonte

    carlospicomonte

    Joined:
    Jan 8, 2019
    Posts:
    11
    [QUOTE = "MNNoxMortem, post: 4136326, miembro: 1168109"] Si es posible, evite la Búsqueda y simplemente arrastre una referencia desde el inspector o configure la referencia mediante el código. Object.Destroy (image.gameObject) destruye gameObject mientras que Object.Destroy (image) destruye el componente. [/ QUOTE]
    ;);)
     
    MNNoxMortem likes this.