Search Unity

[Closed] More help with coding for a tag game

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

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

    Travis13

    Joined:
    Aug 3, 2015
    Posts:
    2
    My game is a tag game and each player who are each a different colours (blue,orange,pink and green) have a different script.The one below is the green characters script as it refrences each of the other characters colours scripts.For some stupid reason the scripts are identical but i make the pink start as it,they can tag the orange but no one else and then the orange can tag no one.Any help on why would be great!




    public GameObject itObject;
    public bool isIt;

    private BlueTagController blueWarrior;
    private OrangeTagController orangeWarrior;
    private PinkTagController pinkWarrior;
    void Start ()
    {
    itObject.SetActive (false);
    isIt = false;
    blueWarrior = FindObjectOfType<BlueTagController> ();
    orangeWarrior = FindObjectOfType<OrangeTagController> ();
    pinkWarrior = FindObjectOfType<PinkTagController> ();
    }

    void Update ()
    {
    if (isIt == false)
    {
    itObject.SetActive (false);
    }

    if (isIt)
    {
    itObject.SetActive (true);
    }


    }

    public void OnTriggerEnter2D (Collider2D other)
    {
    if (other.name == "Warrior_Orange") {
    if (orangeWarrior.isIt == false && isIt == true)
    {
    orangeWarrior.isIt = true;
    isIt = false;
    }

    if (orangeWarrior.isIt == true)
    {
    orangeWarrior.isIt = false;
    isIt = true;
    }
    }

    if (other.name == "Warrior_Pink") {
    if (pinkWarrior.isIt == false && isIt == true)
    {
    pinkWarrior.isIt = true;
    isIt = false;
    }

    if (pinkWarrior.isIt == true)
    {
    pinkWarrior.isIt = false;
    isIt = true;
    }
    }

    if (other.name == "Warrior_Blue") {
    if (blueWarrior.isIt == false && isIt == true)
    {
    blueWarrior.isIt = true;
    isIt = false;
    }

    if (blueWarrior.isIt == true)
    {
    blueWarrior.isIt = false;
    isIt = true;
    }
    }
    }
    }
     
  2. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    Can you please learn to use code tag properly?
    http://forum.unity3d.com/threads/using-code-tags-properly.143875/

    -

    Please don't make duplicate posts. If you have already posted, and no one answers, please find a way to add to or refresh your post with new information. It is often best to keep trying to solve your own problem, and post what you've tried since the previous post. This will show people that you are working hard to help your self and will also show the community what stage you are at in solving your problem, so members can help more effectively.
    -

    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.