Exemplo n.º 1
0
    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (playerAction != PlayerAction.Death)
        {
            if (collision.gameObject.tag == "Trap" ||
                collision.gameObject.tag == "KillPlace" ||
                collision.gameObject.tag == "BindWeed")
            {
                if (canDie)
                {
                    //StartCoroutine(GameObject.FindObjectOfType<SceneFader>().FadeAndLoadScene(SceneFader.FadeDirection.In, sceneName));
                    FindObjectOfType <SceneChanger>().LoadNewScene();
                    playerAction = PlayerAction.Death;
                }

                Vector2 opossingBody = Vector2.zero;
                if (collision.GetComponent <Rigidbody2D>() != null)
                {
                    opossingBody = collision.GetComponent <Rigidbody2D>().velocity;
                }

                if (!grounded)
                {
                    ForceY = opossingBody.y == 0 ? HelperMaxCollisionVelocity(rgdb.velocity.y * -0.7f) : HelperMaxCollisionVelocity(opossingBody.y);
                }
                ForceX = opossingBody.x == 0 ? HelperMaxCollisionVelocity(rgdb.velocity.x * -1f) : HelperMaxCollisionVelocity(opossingBody.x);
            }

            if (collision.gameObject.tag == "Rope")
            {
                Debug.Log("Rope");
                ropeHangingActions();
            }

            if (collision.gameObject.tag == "ClimbWall")
            {
                Debug.Log("Should Climb");
                ropeHangingActions();
                HangUpWall = true;
            }

            if (collision.gameObject.tag == "PushingTotem")
            {
                //transform.Translate(15, 0, 0, Space.World);
                ForceX = pushingTotemForce * Mathf.Sign(collision.gameObject.transform.lossyScale.x);
            }

            if (collision.gameObject.tag == "RopeEnd")
            {
                ropeEnd = true;
            }

            if (collision.gameObject.tag == "EnergyPlus" && canRecieveItems)
            {
                canRecieveItems = false;
                Debug.Log("Collision");
                Debug.Log(ElfStatus.maxTotalEnergy);
                ElfStatus.maxTotalEnergy += 1;
                //FindObjectOfType<SceneChanger>().CurrentScene();
                //Destroy(collision.gameObject);
                StartCoroutine(LateCall(collision.gameObject.GetComponent <BoxCollider2D>()));
                energyController.CreateEnergyBar();
            }
        }
    }