Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

How to change Tag by script?

Discussion in 'Scripting' started by leegod, Jun 22, 2010.

Thread Status:
Not open for further replies.
  1. leegod

    leegod

    Joined:
    May 5, 2010
    Posts:
    2,488
    How to change Tag by scripting?

    I want if enemy dead, I want to change its tag from [enemy] to another or untagged. Thus become no more enemy.

    Can I do this?
     
  2. Landern

    Landern

    Joined:
    Dec 21, 2008
    Posts:
    354
    As long as the Tag exists, you can access and set it with:

    transform.gameObject.tag = "SomeTagName";
     
  3. BlackMantis

    BlackMantis

    Joined:
    Feb 7, 2010
    Posts:
    1,475
    Does it have to have the transform infront of the GameObject ?

    Or can it be gameObject.tag = "SomeTagName"; ? :D
     
  4. BoredKoi

    BoredKoi

    Joined:
    Jun 18, 2009
    Posts:
    162
    Either way is fine.
     
  5. levkrinitsky

    levkrinitsky

    Joined:
    May 22, 2021
    Posts:
    2
    Thank you!!!
     
    Westland, e_person and muddss like this.
  6. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,777
    * Brand new account, first reply
    * Reply that adds nothing to the conversation
    * The last comment in this thread is ELEVEN YEARS OLD



    This one goes in the necroposting hall of fame
     
    Westland, e_person, Bunny83 and 2 others like this.
  7. koirat

    koirat

    Joined:
    Jul 7, 2012
    Posts:
    2,090
    It's probably a bot.
     
    Westland and August_Jade like this.
Thread Status:
Not open for further replies.