Example #1
0
    //collision detection
    void OnCollisionEnter2D(Collision2D coll)
    {
        //if its not attached to something then its just the beginning of the game
        if (checkBombState.isAttached() == false)
        {
            //if what we are colliding with is the bomb then check which player we are
            if (coll.gameObject.tag == "TheBomb")
            {
                //if we are player red, then set that it has been attached and to the red player
                if (transform.tag == "Player1")
                {
                    checkBombState.setRedHasBomb();
                    checkBombState.setAttached();
                    coll.gameObject.GetComponent <Transform> ().SetParent(redBack);
                    gameObject.GetComponent <Unattach_Bomb>().enabled = false;
                    //Debug.Log("Red has it");

                    //if we are player blue, then set that it has been attached and to the blue player
                }
                else if (transform.tag == "Player3")
                {
                    checkBombState.setBlueHasBomb();
                    checkBombState.setAttached();
                    coll.gameObject.GetComponent <Transform> ().SetParent(blueBack);
                    gameObject.GetComponent <Unattach_Bomb>().enabled = false;
                    //Debug.Log("blue has it");
                }
                else if (transform.tag == "Player4")
                {
                    checkBombState.setGreenHasBomb();
                    checkBombState.setAttached();
                    coll.gameObject.GetComponent <Transform> ().SetParent(greenBack);
                    gameObject.GetComponent <Unattach_Bomb>().enabled = false;
                    //Debug.Log("green has it");
                }
                else if (transform.tag == "Player2")
                {
                    checkBombState.setYellowHasBomb();
                    checkBombState.setAttached();
                    coll.gameObject.GetComponent <Transform> ().SetParent(yellowBack);
                    gameObject.GetComponent <Unattach_Bomb>().enabled = false;
                    //Debug.Log("yellow has it");
                }
                else
                {
                    //do nothing;
                    //Debug.Log("Nothing interesting here");
                }

                //destroy the bomb's rigid body as we don't need its physics
                Destroy(coll.gameObject.GetComponent <Rigidbody2D> ());
                //disable the circle collider as it is not part of the player's body collider
                coll.gameObject.GetComponent <CircleCollider2D>().enabled = false;
            }
        }

        //Debug.Log (transform.tag + "has " +transform.childCount + " children");
    }
Example #2
0
 //this collision method is written as a one way collision
 //the only collision it sets off is the one who doesn't have the bomb
 void OnCollisionEnter2D(Collision2D coll)
 {
     try{
         //if our unattach/steal script is active then we can have collision
         if (coll.gameObject.tag != "TheGround" && coll.gameObject.tag != "Untagged")
         {
             if (this.isActiveAndEnabled && !coll.gameObject.GetComponent <Unattach_Bomb>().isActiveAndEnabled)
             {
                 //If Blue was active, and collided, then blue steals; set blue has bomb
                 if (transform.tag == "Player3")
                 {
                     bombState.setBlueHasBomb();
                 }
                 //else blue was not active and red was, set red has bomb
                 else if (transform.tag == "Player1")
                 {
                     bombState.setRedHasBomb();
                 }
                 //else blue,red was not active and green was, set green has bomb
                 else if (transform.tag == "Player4")
                 {
                     bombState.setGreenHasBomb();
                 }
                 else if (transform.tag == "Player2")
                 {
                     bombState.setYellowHasBomb();
                 }
                 //if we collided, then that means an exchange happened
                 //call the waittime function to reactivate the unattach/steal script
                 //of the previous bomb owner
                 sorry.enabled = true;
                 StartCoroutine(waitTime(coll));
             }
         }
     }
     catch (Exception e) {
         //Debug.Log("Caught Error in Unattach");
     }
 }