예제 #1
0
    // Update is called once per frame
    void Update()
    {
        if (previousVelocity != 0 && Rb.velocity.y == 0)
        {
            FindObjectOfType <AudioManager>().Play("floorImpact");
        }
        if (!animator.GetBool("Death"))
        {
            keyNumber.text = collectedKey.ToString() + "/" + keyOnMap.ToString();

            // set element into storedMagic, depends on OntriggerEnter2D and Exit
            if (Input.GetButtonDown("PickUpMagic")) //PICKUPMAGIC
            {
                if (storedMagicFlag == "Fire")
                {
                    FindObjectOfType <AudioManager>().Play("fireElementPickUp");
                    StartCoroutine(DisablePowerUp(powerUp));
                    storedMagic = playerMagic.FIRE;
                }
                else if (storedMagicFlag == "Ice")
                {
                    FindObjectOfType <AudioManager>().Play("iceElementPickUp");
                    StartCoroutine(DisablePowerUp(powerUp));
                    storedMagic = playerMagic.ICE;
                }
            }

            //if !isAttacking to avoid moving while attacking
            if (controller.finished == true)
            {
                horizontalMove = 0;
            }
            else
            {
                horizontalMove = Input.GetAxisRaw("Horizontal") * runSpeed; //outside the if !cover to avoid keep moving when run and cover bug
            }
            animator.SetFloat("Speed", Mathf.Abs(horizontalMove));
            animator.SetFloat("VelocityY", Rb.velocity.y); //detects the Y speed for jump animation
            bool jumpButton = Input.GetButtonDown("Jump");

            bool useMagicButton = Input.GetButtonDown("UseMagic"); //e

            //When activate magic, check storadMagic and use that magic, if same element is in use set refreshMagic as true (important for ElementIconEffect). After activating set storadmagig to Neutral
            if (useMagicButton)
            {
                if (storedMagic.ToString() == "FIRE")                //MAGIC USE
                {
                    FindObjectOfType <AudioManager>().Play("fireUse");
                    FindObjectOfType <AudioManager>().Play("usingMagic");
                    StartCoroutine(ShortAnimationPlay("UseMagic"));
                    ppEffects.activateChromaticAberration();                     //postProcessing effect

                    if (activeMagic.ToString() == "FIRE")
                    {
                        refreshMagic = true;
                    }
                    else
                    {
                        activeMagic = playerMagic.FIRE;
                    }
                }
                else if (storedMagic.ToString() == "ICE")                //MAGIC USE
                {
                    FindObjectOfType <AudioManager>().Play("iceUse");
                    FindObjectOfType <AudioManager>().Play("usingMagic");
                    StartCoroutine(ShortAnimationPlay("UseMagic"));
                    ppEffects.activateChromaticAberration();                     //postProcessing effect

                    if (activeMagic.ToString() == "ICE")
                    {
                        refreshMagic = true;
                    }
                    else
                    {
                        activeMagic = playerMagic.ICE;
                    }
                }
                storedMagic = playerMagic.NEUTRAL;
            }

            if (!playerIsCovering)
            {
                if (jumpButton)
                {
                    jump = true;
                }
            }


            if (Input.GetButtonDown("Cover") && horizontalMove == 0 && Rb.velocity.y == 0)     //if we press cover and we are not moving
            {
                playerIsCovering = true;
                animator.SetBool("IsCovering", true);
            }

            if (Input.GetButtonUp("Cover") && playerIsCovering) //stop covering
            {
                playerIsCovering = false;
                animator.SetBool("IsCovering", false);
            }
        }        //if (!animator.GetBool("Death"))
        else
        {
            StartCoroutine("Respawn");
            horizontalMove = 0;
            animator.SetFloat("VelocityY", 0);             //cutre
        }
        previousVelocity = Rb.velocity.y;
    }