0
\$\begingroup\$

I want to destroy any graphic component on a gameobject , example is image,raw image, sprite , ect .But i don't have the list of all graphic component so i don't know how to loop through it . The reason is because i want to replace the component with the same type , for example i want to add Text component , but i can't add it if there is already graphic component attached in the gameobject because there can only be one graphic component in a gameobject , so i need to destroy the graphic component first , how do i do it ?

I personally prefer the answer on c# but any programming language is accepted !

\$\endgroup\$
3
  • 1
    \$\begingroup\$ Maybe adding what you're trying to achieve, i.e. the reason why you need this would help you get better answers. \$\endgroup\$ Commented Sep 19, 2020 at 11:38
  • \$\begingroup\$ Why destroy and add new when you could just modify the existing component in place? Or add a child object with the component you want. \$\endgroup\$ Commented Sep 19, 2020 at 13:37
  • \$\begingroup\$ @Vaillancourt i want to add Text component but i can't add it if there's already graphic component such as Image , Sprite , Raw Image , ect . i already clearly said it in the question. DMGregory because the component doesn't exist so i need to add new one but i cant if there is already same type of component in the gameobject , Text is a graphic component Image is a graphic component ,there can only be one graphic component BUT i don't have the full list of graphic component (as far as i know) so i can't delete the existing graphic component if i don't know what it is. \$\endgroup\$ Commented Sep 22, 2020 at 13:49

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.