コード例 #1
0
ファイル: ShipController.cs プロジェクト: blaquenkot/ship
    void OnCollisionEnter2D(Collision2D collision)
    {
        float damage       = Mathf.Sqrt(collision.relativeVelocity.magnitude);
        float colliderMass = collision.collider.GetComponent <Rigidbody2D>().mass;
        float totalMass    = colliderMass + Rigidbody.mass;

        // Damage proportional to the collider's mass
        TakeDamage(damage * colliderMass / totalMass);
        IDamageable damageable = collision.collider.GetComponent <IDamageable>();

        if (damageable != null)
        {
            // Damage proportional to the ship's mass
            bool killed = damageable.TakeDamage(damage * Rigidbody.mass / totalMass);
            if (killed)
            {
                WorldController.AddPoints(1);

                if (damageable.IsEnemy())
                {
                    WorldController.EnemyKilled(collision.transform.position, false);
                }
            }
        }

        Shake();
    }
コード例 #2
0
    void OnCollisionEnter2D(Collision2D collision)
    {
        IDamageable damageable = collision.collider.gameObject.GetComponent <IDamageable>();

        if (damageable != null)
        {
            damageable.TakeDamage(9999999);
            if (WorldController)
            {
                WorldController.AddPoints(1);

                if (damageable.IsEnemy())
                {
                    WorldController.EnemyKilled(collision.transform.position, true);
                }
            }
        }
    }
コード例 #3
0
ファイル: ShotController.cs プロジェクト: blaquenkot/ship
    void OnCollisionEnter2D(Collision2D collision)
    {
        IDamageable damageable = collision.collider.gameObject.GetComponent <IDamageable>();

        if (damageable != null)
        {
            bool killed = damageable.TakeDamage(HitPower);
            if (WorldController && killed)
            {
                WorldController.AddPoints(1);

                if (damageable.IsEnemy())
                {
                    WorldController.EnemyKilled(collision.transform.position, false);
                }
            }

            AudioSource.PlayClipAtPoint(HitSound, transform.position);
        }


        Destroyed(true);
    }