Search Unity

[Closed] Tag game not working help needed!

Discussion in 'Community Learning & Teaching' started by Travis13, Nov 15, 2015.

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

    Travis13

    Joined:
    Aug 3, 2015
    Posts:
    2
    I am making a tag game on unity and to show how someone is it I change their tags.Here is my code for my blue warrior character (the other characters in the tag game are called as probably guessed Warrior_Orange Warrior_Pink Warrior_Blue and Warrior_Green).The game does not work,as only certain people can be tagged and once someone is tagged they cannot be tagged again,any help would be appreciated XD

    public GameObject itObject;
    public bool isIt;
    public GameObject orangeWarrior;
    public GameObject greenWarrior;
    public GameObject pinkWarrior;

    void Start ()
    {
    itObject.SetActive (false);
    gameObject.tag = "NotIt";
    }

    void Update ()
    {
    if (gameObject.tag == "NotIt")
    {
    itObject.SetActive (false);
    }

    if (gameObject.tag == "It")
    {
    itObject.SetActive (true);
    }


    }

    void OnTriggerEnter2D (Collider2D other)
    {
    if (other.name == "Warrior_Orange" )
    {
    if (other.tag == "NotIt" && gameObject.tag == "It")
    {
    Debug.Log("OrangeNowIt");
    gameObject.tag = "NotIt";
    orangeWarrior.tag = "It";
    }

    if (other.tag == "It")
    {
    Debug.Log("OrangeTaggedYou");
    gameObject.tag = "It";
    orangeWarrior.tag = "NotIt";
    }
    }

    if (other.name == "Warrior_green")
    {
    if (other.tag == "NotIt" && gameObject.tag == "It")
    {
    Debug.Log("GreenNowIt");
    gameObject.tag = "NotIt";
    greenWarrior.tag = "It";
    }

    if (other.tag == "It")
    {
    Debug.Log("GreenTaggedYou");
    gameObject.tag = "It";
    greenWarrior.tag = "NotIt";
    }
    }

    if (other.name == "Warrior_Pink")
    {
    if (other.tag == "NotIt" && gameObject.tag == "It")
    {
    Debug.Log("PinkNowIt");
    gameObject.tag = "NotIt";
    pinkWarrior.tag = "It";
    }

    if (other.tag == "It")
    {
    Debug.Log("PinkTaggedYou");
    gameObject.tag = "It";
    pinkWarrior.tag = "NotIt";
    }
    }
    }
    }
     
  2. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    Please use code tags when posting code on the forum.
    http://forum.unity3d.com/threads/using-code-tags-properly.143875/

    Please Note:

    The Teaching section is to discuss and support specific Teaching material and the Learn section of the website. For basic support please use the relevant section of the forum. Some suggestions would be:

    http://forum.unity3d.com/forums/editor-general-support.10/ for General Support
    http://forum.unity3d.com/forums/scripting.12/ for Scripting

    As this topic is not specific to Teaching Material or the Learn Section of our site, I am closing this thread.
     
Thread Status:
Not open for further replies.