Example #1
0
    void Update()
    {
        if (!isPaused)
        {
            if (isLocked)
            {
                audioData.Stop(); //stops the whip sound from playing when miles is locked on the floor changing mechanism, but hasnt chosen a direction
                whipAnim.Play("MilesWhipPulledBackIdleStop");
                MilesFrontWalk.enabled = false;
                MilesBackWalk.enabled  = false;

                foreach (GameObject sprites in MilesSprites)
                {
                    sprites.GetComponent <SpriteRenderer>().enabled = false;
                }

                if (Input.GetMouseButtonDown(0) || Input.GetMouseButtonDown(1) || Input.GetButtonDown("Fire3") || Input.GetButtonDown("Fire5"))
                {
                    audioData.clip = audioClipArray[11]; //plays whip sound after player makes a direction choice
                    audioData.PlayOneShot(audioData.clip);
                    playedOnce = false;
                    isLocked   = false;
                    shake.triggerShakeBig();
                    whipAnim.Play("MilesWhipPulledBackIdle");
                }
            }

            if (notMoving && !isJumping && !isRolling && !justJumped && isGrounded && !isWhipping && !bigDropQuake)//trying to stop sliding
            {
                rb.drag = 2f;
            }
            else
            {
                rb.drag = 0.2f;
            }
            if (isDead)
            {
                SceneManager.LoadScene("DeathScene");
            }
            else if (isWhipping && isGrounded && !isLocked && !justJumped && !isRolling && !playedOnce)
            {
                foreach (GameObject sprites in MilesSprites)
                {
                    sprites.GetComponent <SpriteRenderer>().enabled = false;
                }

                MilesFrontWalk.enabled = false;
                MilesBackWalk.enabled  = false;
                whipAnim.Play("MilesWhippingFrameByFrame"); //whip extending animation

                if (!isLocked && playedOnce == false)
                {
                    audioData.clip = audioClipArray[11];
                    audioData.PlayOneShot(audioData.clip);
                    StartCoroutine(WhipAnimationDelay());
                    playedOnce = true;
                }
            }
            else if (!isWhipping && !isLocked)
            {
                // moves character
                if ((Input.GetAxis("Horizontal") != 0) || (Input.GetAxis("Vertical") != 0))
                {
                    notMoving = false;
                }
                else
                {
                    notMoving = true;
                }
                if (MilesFrontWalk && !facingFront)
                {
                    TurnOffFrontWalk();
                }

                if (!stayStill)
                {
                    if (!facingFront)
                    {
                        transform.Translate(Input.GetAxis("Horizontal") * speed * Time.deltaTime, 0f, Input.GetAxis("Vertical") * speed * Time.deltaTime);
                    }
                    else
                    {
                        transform.Translate(Input.GetAxis("Horizontal") * speed * Time.deltaTime, 0f, -1 * (speed + 3) * Time.deltaTime);
                    }

                    if (Input.GetMouseButton(0) || Input.GetButtonDown("Fire4"))
                    {
                        if (isGrounded && !isRolling && !justJumped)
                        {
                            isWhipping = true;
                            //Debug.Log("Whipping");
                        }
                    } //press mouse button to whip

                    if (Input.GetAxis("Horizontal") > 0)
                    {
                        //player is going right
                        isBackTurned         = false;
                        transform.localScale = new Vector3(defaultScale, transform.localScale.y, transform.localScale.z);
                        whip.sortingOrder    = 10;
                        if (facingFront && !notMoving)
                        {
                            RunAnimation();
                        }
                        else if (facingFront && notMoving)
                        {
                            anim.Play("MilesIdle");
                        }
                    }
                    else if (Input.GetAxis("Horizontal") < 0)
                    {
                        //player is going left
                        isBackTurned         = false;
                        transform.localScale = new Vector3(-defaultScale, transform.localScale.y, transform.localScale.z);
                        whip.sortingOrder    = 0;
                        if (facingFront && !notMoving)
                        {
                            RunAnimation();
                        }
                        else if (facingFront && notMoving)
                        {
                            anim.Play("MilesIdle");
                        }
                    }
                    //character moving toward camera
                    if (Input.GetAxis("Vertical") < 0)
                    {
                        if (Input.GetAxis("Horizontal") == 0)
                        {
                            foreach (GameObject sprites in MilesSprites)
                            {
                                sprites.GetComponent <SpriteRenderer>().enabled = false;
                            }

                            MilesFrontWalk.enabled = true;
                            MilesBackWalk.enabled  = false;

                            if (!justJumped && isGrounded)
                            {
                                frontMiles.Play("MilesFrontRunCycle");
                            }

                            isBackTurned = false;
                        }
                    }
                    //character moving away from camera
                    if (Input.GetAxis("Vertical") > 0)
                    {
                        if (Input.GetAxis("Horizontal") == 0)
                        {
                            foreach (GameObject sprites in MilesSprites)
                            {
                                sprites.GetComponent <SpriteRenderer>().enabled = false;
                            }
                            if (facingFront)//these if statments make sure the player cant face away from the camera when in auto run "Boulder" mode
                            {
                                frontMiles.Play("MilesFrontRunCycle");
                            }
                            else if (!facingFront)
                            {
                                MilesBackWalk.enabled  = true;
                                MilesFrontWalk.enabled = false;
                            }
                            if (!justJumped && isGrounded)
                            {
                                backMiles.Play("MilesBackRunCycle");
                            }
                            isBackTurned = true;
                        }
                    }

                    if (!isGrounded)
                    {
                        timeInAir += Time.deltaTime;
                        //Debug.Log(timeInAir);
                    }

                    if (timeInAir > maxAirTime)
                    {
                        if (timeInAir > 6f)
                        {
                            bigDropQuake = false;
                        }
                        else if (timeInAir < 6f)
                        {
                            bigDropQuake = true;
                        }
                    }

                    if (Input.GetKeyDown(KeyCode.F))
                    {
                        if (isGrounded && notMoving)
                        {
                            anim.Play("MilesFart");
                            fartParticles.Play();
                        }

                        if (!isGrounded && (!notMoving || notMoving))
                        {
                            anim.Play("MilesFartAirborne");
                            fartParticles.Play();
                        }

                        if (!isGrounded && !fartJumpCooldown)
                        {
                            //rb.velocity = new Vector3(rb.velocity.x, jumpForce, rb.velocity.z);
                            fartJumpCooldown = true;
                            fartParticles.Play();
                        }
                    }

                    // roll
                    if (isGrounded && !isRolling && (Input.GetKeyDown("left shift") || Input.GetButtonDown("Fire3")))
                    {
                        if (!facingFront && !notMoving)
                        {
                            speed    += rollSpeed;
                            isRolling = true;
                            RollAnimation();
                            StartCoroutine(RollBack());
                        }
                        else if (facingFront && !isRolling) //removing !isRolling causes the player to infinitely speedup
                        {
                            speed           += rollSpeed;
                            isRolling        = true;
                            frontMiles.speed = 1.8f;
                            frontMiles.Play("MilesFrontRunCycle");
                            StartCoroutine(RollBack());
                        }
                    }
                    // roll back
                    if (isGrounded && rollStop)
                    {
                        speed    -= rollSpeed;
                        isRolling = false;
                        rollStop  = false;
                    }

                    // applies force vertically if the space key is pressed
                    if (isGrounded && (Input.GetKeyDown("space") || Input.GetButton("Fire1")))
                    {
                        if (justJumped == false && isJumping == false)
                        {
                            rb.velocity = new Vector3(rb.velocity.x, jumpForce, rb.velocity.z);
                            justJumped  = true;
                            isJumping   = true;
                            JumpAnimation();
                            PlayerJumpSound();
                            StartCoroutine(JumpReset());
                        }
                    }

                    // stairs checker
                    if (isGrounded)
                    {
                        newPosition = gameObject.transform.position.y;

                        if (newPosition > originalPosition)
                        {
                            isStairs = true;
                        }
                        else
                        {
                            isStairs = false;
                        }

                        originalPosition = gameObject.transform.position.y;
                    }
                }
            }
        }
        // coins
        if (isGreen > 0)
        {
            if (counterGreen != greenValue)
            {
                score += 1;
                ScoreDisplay();
                text.text += score;
                counterGreen++;

                if (counterGreen == greenValue)
                {
                    counterGreen = 0;
                    isGreen--;
                }
            }
        }
        if (isGold > 0)
        {
            if (counterGold != goldValue)
            {
                score += 1;
                ScoreDisplay();
                text.text += score;
                counterGold++;

                if (counterGold == goldValue)
                {
                    counterGold = 0;
                    isGold--;
                }
            }
        }
        if (isSilver > 0)
        {
            if (counterSilver != silverValue)
            {
                score += 1;
                ScoreDisplay();
                text.text += score;
                counterSilver++;

                if (counterSilver == silverValue)
                {
                    counterSilver = 0;
                    isSilver--;
                }
            }
        }
    }