コード例 #1
0
ファイル: TankBullet.cs プロジェクト: KobeyMyhre/TankFight
    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.tag == "Player")
        {
            var hitable = collision.transform.parent.GetComponent <IDamageable>();
            var tankGun = collision.transform.parent.GetComponent <TankGun>();
            if (hitable != null && tankGun.playerNum != playerNum)
            {
                Vector2 dir = collision.transform.position - transform.position;

                float angle     = Vector2.Angle(dir.normalized, collision.transform.up);
                float topBottom = Mathf.Sign(collision.transform.position.y - transform.position.y);
                //Debug.Log(angle);

                if (topBottom == -1 && angle >= 125 && angle <= 180)
                {
                    spawnLilBoom();
                    if (hitable.takeDamage(frontalDamage))
                    {
                        score.updateScore();
                    }
                }
                else
                {
                    spawnBoom();
                    if (hitable.takeDamage(normalDamage))
                    {
                        score.updateScore();
                    }
                    //Debug.Log("side/back");
                }


                //if (angle >= 40 && angle <= 130)
                //{
                //    hitable.takeDamage(sideDamage);
                //    Debug.Log("Side Hit");
                //}
                //else
                //{
                //    hitable.takeDamage(frontalDamage);
                //    Debug.Log("Front/back Hit");
                //}

                me.returnToPool();
            }
        }
        if (collision.tag == "Obstacle" || collision.tag == "Bullet")
        {
            spawnBoom();
            me.returnToPool();
        }
    }
コード例 #2
0
ファイル: TankGrenade.cs プロジェクト: KobeyMyhre/TankFight
 private void OnTriggerEnter2D(Collider2D collision)
 {
     if (collision.tag == "Player")
     {
         var tankGun = collision.transform.parent.GetComponent <TankGun>();
         if (tankGun.playerNum != playerNum)
         {
             spawnBoom();
             Explode();
             me.returnToPool();
         }
     }
 }
コード例 #3
0
 private void OnTriggerEnter2D(Collider2D collision)
 {
     if (collision.tag == "Player")
     {
         var hitable = collision.transform.parent.GetComponent <IDamageable>();
         var tankGun = collision.transform.parent.GetComponent <TankGun>();
         if (hitable != null && tankGun.playerNum != playerNum)
         {
             if (hitable.takeDamage(Damage))
             {
                 score.updateScore();
             }
             spawnBoom();
             me.returnToPool();
         }
     }
 }