Пример #1
0
    public void OnCollisionEnter2D(Collision2D collision)//2
    {
        if (collision == null)
        {
            return;
        }
        if (!collision.gameObject.CompareTag(TagLibrary.playerTag))
        {
            EnemyStats otherStats = collision.gameObject.GetComponent <EnemyStats>();
            if (stats.mass > otherStats.mass)
            {
                Vector2         collisionPoint = collision.contacts[0].point;
                EnemyBaseEngine otherEngine    = collision.gameObject.GetComponent <EnemyBaseEngine>();
                enemyFactory = new EnemyFactory(stats, otherStats, collision.relativeVelocity.magnitude);
                var result = enemyFactory.GetCollisionResult();
                switch (result.initiatorCollisionResult)
                {
                case InitiatorCollisionResult.otherDestroyed:
                    Rize(result);

                    if (result.FullyConsumed)
                    {
                        otherEngine.Deactivate();
                    }
                    else
                    {
                        otherEngine.Deactivate(collisionPoint);
                    }

                    break;

                case InitiatorCollisionResult.noAction:
                    //do nothing???
                    break;

                case InitiatorCollisionResult.bouthDestroyed:
                    otherEngine.Deactivate(collisionPoint);
                    Deactivate(collisionPoint);
                    break;

                case InitiatorCollisionResult.initiatorDestroyed:
                    otherEngine.Rize(result);    //&&

                    if (result.FullyConsumed)
                    {
                        Deactivate();
                    }
                    else
                    {
                        Deactivate(collisionPoint);
                    }

                    break;

                default:
                    break;
                }
            }
        }
    }