private void OnCollisionEnter2D(Collision2D collision)
    {
        GameObject          collider = collision.collider.gameObject;
        PotionEffectsScript pe       = collider.GetComponent <PotionEffectsScript>();

        if (pe != null)
        {
            switch (Type)
            {
            case PotionEffect.Agility:
                pe.ApplyAgility(Duration);
                break;

            case PotionEffect.Burning:
                pe.ApplyBurning(Duration);
                break;

            case PotionEffect.Frozen:
                pe.ApplyFrozen(Duration);
                break;

            case PotionEffect.Poison:
                pe.ApplyPoison(Duration);
                break;

            case PotionEffect.Strength:
                pe.ApplyStrength(Duration);
                break;
            }
            this.gameObject.SetActive(false);
        }
    }
    // Update is called once per frame
    void Update()
    {
        Collider2D[] colliders = Physics2D.OverlapBoxAll(new Vector2(gameObject.transform.position.x, gameObject.transform.position.y), new Vector2(collider.bounds.size.x / 2, collider.bounds.size.y / 2), AffectedLayer);
        for (int i = 0; i < colliders.Length; i++)
        {
            if ((AffectedLayer.value & (1 << colliders[i].gameObject.layer)) > 0)
            {
                PotionEffectsScript pe = colliders[i].GetComponent <PotionEffectsScript>();

                if (pe != null)
                {
                    switch (Type)
                    {
                    case PotionEffect.Agility:
                        pe.ApplyAgility(Duration);
                        break;

                    case PotionEffect.Burning:
                        pe.ApplyBurning(Duration);
                        break;

                    case PotionEffect.Frozen:
                        pe.ApplyFrozen(Duration);
                        break;

                    case PotionEffect.Poison:
                        pe.ApplyPoison(Duration);
                        break;

                    case PotionEffect.Strength:
                        pe.ApplyStrength(Duration);
                        break;
                    }
                    this.gameObject.SetActive(false);
                }
            }
        }
    }
Exemplo n.º 3
0
    void FixedUpdate()
    {
        //GOD MODE
        if (GodMode && jump)
        {
            ApplyJumpForce();
        }

        bool touchesGroundNow = CheckGroundCollision(GroundCheck) || CheckGroundCollision(GroundCheck1) || CheckGroundCollision(GroundCheck2);
        bool canClimb         = CheckLadderCollision();

        float horizontalMove = Input.GetAxisRaw("Horizontal") * MaxSpeed;

        if (currentState != PlayerState.BOW_AIM && Mathf.Abs(horizontalMove) > 0.1f)
        {
            renderer.flipX = horizontalMove < 0;
            animator.SetBool("Move", true);
        }
        else
        {
            animator.SetBool("Move", false);
        }

        float verticalAxis = Input.GetAxisRaw("Vertical");

        if (currentState == PlayerState.CLIMB && Mathf.Abs(horizontalMove) + Mathf.Abs(verticalAxis) > 0.1f)
        {
            animator.SetBool("Frame2", frame2);
            frame2 = !frame2;
        }

        if (currentState == PlayerState.CROUCH || currentState == PlayerState.CROUCH_ATK || currentState == PlayerState.CROUCH_MOVE)
        {
            cc2.size   = new Vector2(0.45f, 0.75f);
            cc2.offset = new Vector2(0f, -0.625f);
        }
        else
        {
            cc2.size   = new Vector2(0.45f, 1.5f);
            cc2.offset = new Vector2(0f, -0.25f);
        }

        bool landed    = !touchesGround && touchesGroundNow;
        bool fell      = touchesGround && !touchesGroundNow;
        bool crouching = !canClimb && verticalAxis < -0.5f;
        bool climbing  = canClimb && (verticalAxis <-0.5f || verticalAxis> 0.5f);

        if (climbing)
        {
            climb = true;
        }
        if (!canClimb)
        {
            climb = false;
        }

        bool bowaim = false;


        if (!attack && currentState == PlayerState.BOW_AIM)
        {
            switch (heldItem)
            {
            case "AR_R": ShootProjectile(heldItem); break;

            case "AR_H": ShootProjectile(heldItem); break;

            case "AR_F": ShootProjectile(heldItem); break;

            case "AR_P": ShootProjectile(heldItem); break;

            case "AR_M": ShootProjectile(heldItem); break;
            }

            inventory.RemoveItem(heldItem);
            if (inventory.GetCount(heldItem) == 0)
            {
                SelectInventoryItem("");
            }
            bowaim = false;
        }


        if (attack && heldItemType != HeldItemType.NONE)
        {
            /*USE ITEM*/
            if (heldItemType == HeldItemType.POTION)
            {
                attack = false;
                switch (heldItem)
                {
                case "PT_R": hps.IncreaseRelative(0.5f); break;

                case "PT_O": pes.ApplyInvisible(60); break;

                case "PT_G": pes.ApplyStrength(30); break;

                case "PT_B": pes.ApplyAgility(30); break;
                }

                inventory.RemoveItem(heldItem);
                SelectInventoryItem("");
            }
            else if (heldItemType == HeldItemType.THROW)
            {
                switch (heldItem)
                {
                case "BOMB": ShootProjectile(heldItem); break;

                case "AF_P": ShootProjectile(heldItem); break;

                case "AF_M": ShootProjectile(heldItem); break;
                }

                if (heldItem == "BOMB")
                {
                    inventory.RemoveItem(heldItem);
                    SelectInventoryItem("");
                }

                attack = false;
            }
            else if (heldItemType == HeldItemType.BOW)
            {
                bowaim = true;
            }
            else if (heldItemType == HeldItemType.THROW_POTION)
            {
                // DISTANCE
                // JAKO THROW NEBO POTION

                switch (heldItem)
                {
                case "PT_V": pes.CancelPoison(); break;

                case "AF_H": pes.CancelFrozen(); break;

                case "AF_F": pes.CancelBurning(); break;

                case "AF_A": pes.CancelPoison(); break;
                }

                switch (heldItem)
                {
                case "PT_V": ShootProjectile(heldItem); break;

                case "AF_H": ShootProjectile(heldItem); break;

                case "AF_F": ShootProjectile(heldItem); break;

                case "AF_A": ShootProjectile(heldItem); break;
                }

                if (heldItem == "PT_V")
                {
                    inventory.RemoveItem(heldItem);
                    SelectInventoryItem("");
                }

                attack = false;
            }
        }


        PlayerState previousState = currentState;

        UpdateState(jump, landed, fell, crouching, attack, climb, bowaim);

        rigidbody2D.MovePosition(transform.position + new Vector3(horizontalMove * GetMovementMult(), spdY, 0));

        if (!climb)
        {
            spdY -= Gravity;
            if (spdY < -0.2f)
            {
                spdY = -0.2f;
            }
        }
        else
        {
            spdY = verticalAxis / 5f;
        }

        if (previousState != PlayerState.JUMP && currentState == PlayerState.JUMP)
        {
            touchesGround = false;
        }
        else
        {
            touchesGround = touchesGroundNow;
        }

        jump = false;
        if (currentState != PlayerState.BOW_AIM)
        {
            attack = false;
        }
    }