コード例 #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
 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();
         }
     }
 }
コード例 #3
0
ファイル: TankGrenade.cs プロジェクト: KobeyMyhre/TankFight
 void Explode()
 {
     Collider2D[] hood = Physics2D.OverlapCircleAll(transform.position, 1);
     foreach (Collider2D obj in hood)
     {
         if (obj.tag == "Player")
         {
             var tankGun = obj.transform.parent.GetComponent <TankGun>();
             if (tankGun.playerNum != playerNum)
             {
                 if (obj.gameObject.transform.parent.GetComponent <IDamageable>().takeDamage(Damage))
                 {
                     score.updateScore();
                 }
             }
         }
     }
 }
コード例 #4
0
 // Update is called once per frame
 void Update()
 {
     Collider2D[] guysOnHill = Physics2D.OverlapCircleAll(transform.position, 2);
     numOnHill = 0;
     foreach (var guy in guysOnHill)
     {
         var isItTank = guy.GetComponentInParent <TankScore>();
         if (isItTank != null)
         {
             numOnHill++;
             guyInHill = isItTank;
         }
     }
     if (numOnHill == 1)
     {
         guyInHill.updateScore();
     }
 }