Exemple #1
0
    private void Update()
    {
        if (Input.GetButtonDown("Interact") && currentObject)
        {
            //Ist dies ein Inventory Objekt?
            if (currentObjectScript.inventory)
            {
                inventory.AddItem(currentObject);
            }
        }

        if (Input.GetButtonDown("Interact") && _endGameObject)
        {
            //Ist dies ein Inventory Objekt?
            if (currentObjectScript.inventory && inventory.InventoryFull() == true)
            {
                inventory.AddItem(_endGameObject);
                GameObject.FindGameObjectWithTag("GameManager").GetComponent <GameStateManager>().YouWin();
            }
        }

        //Benutze die gesammelten Bruchstücke
        if (Input.GetButtonDown("Use") && currentObject)
        {
            Debug.Log("Q was pressed!");
            //Inventar prüfen (ShuttlePiece)
            GameObject ShuttlePiece = inventory.FindItemByType("Nektar");
            if (ShuttlePiece != null)
            {
                //Bruchstücke verwenden - Shuttle Reparieren
                //Von Inventar entfernen
                if (currentObjectScript.inventory)
                {
                    inventory.RemoveItem(inventory.FindItemByType("Nektar"));
                }
            }
            if (ShuttlePiece = null)
            {
                Debug.Log("Can't find a ShuttlePiece!");
            }
        }
    }
    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;
        }
    }