예제 #1
0
    public void OnTriggerEnter2D(Collider2D collision)
    {
        if (destroyed)
        {
            return;
        }

        GameObject _other    = collision.gameObject;
        string     _otherTag = _other.tag;

        if (_otherTag == "EnemyShip")
        {
            enemyExplodeSound.Play();
            // add the score manually, as the energy code only does it on 'natural' object destruction;
            GGS.AddScore(2);
            // ship collision with shields off is a bad thing.
            energy.DoDamage(150, 0, true);
            GameObject  _explo        = Instantiate(enemyExplosion, _other.transform.position, _other.transform.rotation);
            Rigidbody2D _explorb      = _explo.GetComponent <Rigidbody2D>();
            ManagedMob  _enemyManager = _other.GetComponent <ManagedMob>();
            _explorb.velocity = _enemyManager.velocity();

            Destroy(_other);
        }

        if (_otherTag == "EnemyBullet")
        {
            hitSound.Play();
            energy.DoDamage(_other.GetComponent <bullet>().payloadEnergy, 0, true);
            Instantiate(bulletDeath, _other.transform.position, _other.transform.rotation);
            Destroy(_other);
        }
    }
예제 #2
0
    private void OnCollisionEnter2D(Collision2D collision)
    {
        GameObject _other    = collision.gameObject;
        string     _otherTag = _other.tag;
        float      _damage   = 0;

        if (_otherTag == "EnemyShip")
        {
            enemyBounceSound.Play();
            // They will have received the same event, so just damage ourselves
            _damage = enemyCollisionDamage;
            // velocity is immediately halted
            _rb.velocity = new Vector2(0, 0);
            // as is rotation
            _rb.angularVelocity = 0;
        }
        _e.DoDamage(_damage, 4);
    }