Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only.

    Please, do not make any changes to your username or email addresses at id.unity.com during this transition time.

    It's still possible to reply to existing private message conversations during the migration, but any new replies you post will be missing after the main migration is complete. We'll do our best to migrate these messages in a follow-up step.

    On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live.


    Read our full announcement for more information and let us know if you have any questions.

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,498
    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
  6. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,778
    * 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,100
    It's probably a bot.
     
    Westland and August_Jade like this.
Thread Status:
Not open for further replies.