Example #1
0
    private void OnTriggerExit2D(Collider2D col)
    {
        if (!col.CompareTag("Player"))
        {
            return;
        }
        //Ignore the player's circle collider cause that's used for checking if boxes are nearby.
        else if (col.GetType() == typeof(CircleCollider2D))
        {
            return;
        }


        Rigidbody2D       rb2d = col.gameObject.GetComponent <Rigidbody2D>();
        PlayerController  pc   = col.gameObject.GetComponent <PlayerController>();
        DrowningBehaviour db   = col.gameObject.GetComponent <DrowningBehaviour>();

        //rb2d.constraints = RigidbodyConstraints2D.FreezeRotation;

        pc.moveSpeed = previousMoveSpeed;
        pc.airSpeed  = previousAirSpeed;
        Destroy(instantiation);

        db.drownbar.gameObject.SetActive(false);
        db.health            = db.breathTime;
        db.drownbar.maxValue = db.breathTime;
        db.drownbar.value    = db.health;
    }
Example #2
0
    private void OnTriggerStay2D(Collider2D col)
    {
        if (!col.CompareTag("Player"))
        {
            return;
        }
        //Ignore the player's circle collider cause that's used for checking if boxes are nearby.
        else if (col.GetType() == typeof(CircleCollider2D))
        {
            return;
        }


        PlayerController  pc             = col.gameObject.GetComponent <PlayerController>();
        DrowningBehaviour playerDrowning = col.gameObject.GetComponent <DrowningBehaviour>();
        Rigidbody2D       rb2d           = col.gameObject.GetComponent <Rigidbody2D>();

        //If the player is below the maxHeight's y position, he will drown and take damage.
        playerDrowning.CheckHeight(maxHeight);

        if (pc.umbrellaDown && pc.umbrella)
        {
            rb2d.AddForce(Vector2.up * hoverSpeed, ForceMode2D.Force);

            if (instantiation == null)
            {
                CreateParticle(col.transform);
            }
        }
        else
        {
            if (instantiation != null)
            {
                Destroy(instantiation);
            }
        }
    }