Exemplo n.º 1
0
    void OnCollisionEnter2D(Collision2D col)
    {
        if (col.gameObject.tag == "Tank" && MenuUI.getFlag() != 1)     //Is the object we hit a tank?

        {
            Tank tank = col.gameObject.GetComponent <Tank>();    //Get the tank's Tank.cs component.

            //play powerup sound effect
            if (tank.health > 1)
            {
                FindObjectOfType <AudioManager>().Play("mine");
            }
            tank.Damage(damage);
        }

        else if (col.gameObject.tag == "Tank")    //Is the object we hit a tank in multiplayer?

        {
            TankMultiplayer tank = col.gameObject.GetComponent <TankMultiplayer>();  //Get the tank's Tank.cs component.
            //in multiplayer tanks have 1 hp (in current version) so hitting a mine kills them
            tank.Die();
        }

        //play the hit effect every time the ball collides with objects
        GameObject hitEffect1 = Instantiate(hitParticleEffect, transform.position, Quaternion.identity) as GameObject;

        Destroy(hitEffect1, 1.0f);
        Destroy(gameObject);
    }
Exemplo n.º 2
0
    void damageNearbyPlayers()
    {
        //get items overlapping in the collision circle
        Collider2D[] colls = Physics2D.OverlapCircleAll(explosive.position, farAreaEffect);

        //for each item in collision
        foreach (Collider2D col in colls)
        {
            //if it was a tank
            if (col.CompareTag("Tank") && MenuUI.getFlag() != 1)
            {
                Tank  tank     = col.gameObject.GetComponent <Tank>(); //Get the tank's Tank.cs component.
                float distance = Vector3.Distance(col.transform.position, explosive.position);
                //Debug.Log("tank in explosion distance:" + distance);
                int damage = farDamage;
                if (distance <= closeAreaEffect)   //if tank is in the close to the centre Area
                {
                    damage = closeDamage;
                    //Debug.Log("close");
                }
                else if (distance <= mediumAreaEffect)   //if tank is in the middle Area
                {
                    damage = mediumDamage;
                    //Debug.Log("medium");
                }

                //aplly damage to the tank
                tank.Damage(damage);
            }

            //if it was a tank in multiplayer mode
            else if (col.CompareTag("Tank"))
            {
                TankMultiplayer tank     = col.gameObject.GetComponent <TankMultiplayer>(); //Get the tank's Tank.cs component.
                float           distance = Vector3.Distance(col.transform.position, explosive.position);
                //Debug.Log("tank in explosion distance:" + distance);
                int damage = farDamage;
                if (distance <= closeAreaEffect)   //if tank is in the close to the centre Area
                {
                    damage = closeDamage;
                    //Debug.Log("close");
                }
                else if (distance <= mediumAreaEffect)   //if tank is in the middle Area
                {
                    damage = mediumDamage;
                    //Debug.Log("medium");
                }

                //aplly damage to the tank
                tank.Damage(damage);
            }
        }
    }
Exemplo n.º 3
0
    void ProjectileSimple(Collision2D col)
    {
        if (col.gameObject.tag == "Tank" && MenuUI.getFlag() != 1)
        {                                                     //Is the object we hit a tank?
            Tank tank = col.gameObject.GetComponent <Tank>(); //Get the tank's Tank.cs component.

            if (!game.canDamageOwnTank)
            {                            //Can we not damage our own tank?
                if (tank.id != tankId)   //Is the tank we hit not the one that shot this projectile?
                {
                    tank.Damage(damage); //Call the damage function on that tank to damage it.
                }
            }
            else
            {
                tank.Damage(damage);
            }
        }
        else if (col.gameObject.tag == "Tank")
        {//Is the object we hit a tank?
            Debug.Log("tankMultiplayer");
            TankMultiplayer tank = col.gameObject.GetComponent <TankMultiplayer>();

            /*if (!game.canDamageOwnTank)
             * {                       //Can we not damage our own tank?
             *  if (tank.id != tankId)
             *  {                           //Is the tank we hit not the one that shot this projectile?
             *      tank.Damage(damage);                        //Call the damage function on that tank to damage it.
             *  }
             * }*/
            //else
            //{
            tank.Damage(damage);
            //}
        }

        GameObject hitEffect1 = Instantiate(hitParticleEffect, transform.position, Quaternion.identity) as GameObject;

        Destroy(hitEffect1, 1.0f);
        Destroy(gameObject);
    }