Search Unity

renaming tags

Discussion in 'Scripting' started by Zou, Dec 11, 2007.

  1. Zou

    Zou

    Joined:
    Oct 19, 2007
    Posts:
    22
    Can I rename a game object's tag with scripting?
    I would like to rename the "Ball" tag to something else after the trigger.

    Code (csharp):
    1. function OnTriggerExit (col : Collider)
    2. {
    3.     if (col.gameObject.CompareTag("Ball")
    4.     {
    5.          score.AddToScore();
    6.  
    7.     }
    8. }
     
  2. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Code (csharp):
    1. col.gameObject.tag = "SomethingElse";
    --Eric
     
  3. Zou

    Zou

    Joined:
    Oct 19, 2007
    Posts:
    22
    There is an error that said "SomethingElse is not defined!"
     
  4. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    You want to make sure you already have a tag defined with whatever name you're calling it in the script.

    --Eric
     
  5. Zou

    Zou

    Joined:
    Oct 19, 2007
    Posts:
    22
    thanks eric, every thing works