コード例 #1
0
    protected virtual void OnTriggerEnter2D(Collider2D other)
    {
        if (other.tag == "Enemy" && !HitTarget)
        {
            switch (MoveDirection)
            {
            case E_MOVE_DIRECTION.DOWN:
                SoundManager.Instance.PlayImpact(true);
                break;

            case E_MOVE_DIRECTION.RIGHT:
                SoundManager.Instance.PlayImpact( );
                break;
            }

            HitTarget = true;
            if (SpawnImpact && ImpactEffect != null)
            {
                Quaternion randomRot = UnityEngine.Random.rotation;
                randomRot.x = randomRot.y = 0f;
                GameObject effect = Instantiate(ImpactEffect, transform.position, randomRot) as GameObject;
                Destroy(effect, 2.0f);
            }

            EnemyUnit enemy = other.GetComponent <EnemyUnit>( );
            if (enemy == null)
            {
                return;
            }

            enemy.ApplyDamage(Damage);
            Destroy(gameObject);
        }
    }