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;
                }
            }
        }
    }
Example #2
0
    public void OnCollisionEnter2D(Collision2D collision)
    {
        EnemyBaseEngine enemyBaseEngine = collision.gameObject.GetComponent <EnemyBaseEngine>();

        if (enemyBaseEngine == null)
        {
            return;
        }
        PlayerInteractionEffect playerInteractionEffect = PlayerInteractionCounter.GerInteractionResult(enemyBaseEngine);

        switch (playerInteractionEffect)
        {
        case PlayerInteractionEffect.fullConsume:
            FullConsume(enemyBaseEngine.stats);
            enemyBaseEngine.Deactivate();
            return;

        case PlayerInteractionEffect.partialConsume:
            Vector2 collisionPointPC = collision.contacts[0].point;
            PartialConsume(enemyBaseEngine.stats);
            enemyBaseEngine.Deactivate(collisionPointPC);
            return;
        }
        Vector2 collisionPoint = collision.contacts[0].point;
        // if (enemyBaseEngine.stats.mass * enemyBaseEngine.stats.solidValue / Consts.playerStrongMutipluer < PlayerStats.instance.Mass * PlayerStats.instance.SolidValue)
        // {
        //     FullConsume(enemyBaseEngine.stats);
        //     enemyBaseEngine.Deactivate();
        //     return;
        // }
        //Vector2 collisionPoint = collision.contacts[0].point;
        // if (enemyBaseEngine.stats.mass * enemyBaseEngine.stats.solidValue / Consts.playerAlsoStrongMutipluer < PlayerStats.instance.Mass * PlayerStats.instance.SolidValue)
        // {
        //     PartialConsume(enemyBaseEngine.stats);
        //     enemyBaseEngine.Deactivate(collisionPoint);
        //     return;
        // }
        // if (enemyBaseEngine.stats.mass / Consts.massiveButNonSolidMass < PlayerStats.instance.Mass
        //     && enemyBaseEngine.stats.solidValue* Consts.massiveButNonSolidSloidValue < PlayerStats.instance.SolidValue)
        // {
        //    // Vector2 collisionPoint = collision.contacts[0].point;
        //     PartialConsume(enemyBaseEngine.stats);
        //     enemyBaseEngine.Deactivate(collisionPoint);
        //     return;
        // }
        Vector2 jumpBackDirection = (Vector2)AllObjectData.instance.go.transform.position - collisionPoint;

        print("Jump Back");
        PlayerMovement.instance.AddForce(jumpBackDirection.normalized);
        LoseMass(); //Jump back losing mass//
    }
 protected virtual void CheckDestroy(object sender, EventArgs e) //2
 {
     if (                                                        /*(Mathf.Abs(_enemyBaseEngine.transform.position.x - AllObjectData.instance.posX) > AllIndependentData.instance.cameraXWidth * 4) ||*/
         MainCount.instance.
         IsOutRanged(_enemyBaseEngine.transform, AllObjectData.instance.go.transform, Consts.maxObjectDistance))
     {
         MainCount.instance.TimerEverySecond -= CheckDestroy;
         _enemyBaseEngine.Deactivate();
     }
 }