void Update()
    {
        // Flip the sprite when we change x/y input
        if (Input.GetKey("left"))
        {
            flip.FlipSprite(Flip.Side.left);
        }
        if (Input.GetKey("right"))
        {
            flip.FlipSprite(Flip.Side.right);
        }


        if (characterController.isGrounded)
        {
            // We are grounded, so recalculate
            // move direction directly from axes

            moveDirection  = new Vector3(Input.GetAxis("Horizontal"), 0.0f, Input.GetAxis("Vertical"));
            moveDirection *= speed;

            if (Input.GetButton("Jump"))
            {
                moveDirection.y = jumpSpeed;
            }
        }

        // Apply gravity. Gravity is multiplied by deltaTime twice (once here, and once below
        // when the moveDirection is multiplied by deltaTime). This is because gravity should be applied
        // as an acceleration (ms^-2)
        moveDirection.y -= gravity * Time.deltaTime;

        // Move the controller
        characterController.Move(moveDirection * Time.deltaTime);
    }
Exemplo n.º 2
0
    // Update is called once per frame
    void Update()
    {
        // Check for closeness
        bool playerIsClose = PlayerIsClose();

        if (playerIsClose)
        {
            Debug.Log("The player's close!");
            activeCircle.enabled = PlayerIsClose();

            // Flip to face player
            if (GameObject.Find("Player").transform.position.x < transform.position.x)
            {
                flip.FlipSprite(Flip.Side.left);
            }
            if (GameObject.Find("Player").transform.position.x > transform.position.x)
            {
                flip.FlipSprite(Flip.Side.right);
            }

            // Enable dialogue box
            if (dialogueGroup.alpha < 1)
            {
                dialogueGroup.alpha = Mathf.Min(dialogueGroup.alpha + ALPHA_SPEED, 1.0f);
            }

            // Update speech box
            if (Input.GetKey("z") && speech.text == dialogue.content[dialogue.targetIndex])
            {
                dialogue.Increment();
                speech.text = "";
            }
            if (speech.text != dialogue.content[dialogue.targetIndex])
            {
                speech.text = dialogue.content[dialogue.targetIndex].Substring(0, speech.text.Length + 1);
            }
            //Debug.Log(speech.text);
        }
        else
        {
            speech.text = "";
            if (dialogueGroup.alpha > 0)
            {
                dialogueGroup.alpha = Mathf.Max(dialogueGroup.alpha - ALPHA_SPEED, 0.0f);
            }
            flip.FlipSprite(flip.startingFacing);
        }
    }
Exemplo n.º 3
0
    public void MoveAnalog(float moveX, float moveY)
    {
        Animation.SetFloat("XMovement", Mathf.Abs(moveX));

        //Apply the velocity of the player
        if (_player.onRope == null)
        {
            if (_player.onLadder)
            {
                bool leftFoot  = _jump.GetGrounded(true);
                bool rightFoot = _jump.GetGrounded(false);

                if (!leftFoot && !rightFoot)
                {
                    Animation.ResetTrigger("Jump");
                    Animation.SetTrigger("Climbing");

                    Animation.SetFloat("ClimbingSpeed", Mathf.Abs(moveY));
                    Animation.speed = Animation.GetFloat("ClimbingSpeed");
                }
                else
                {
                    Animation.ResetTrigger("Climbing");
                    Animation.SetTrigger("Land");
                    Animation.speed = 1f;
                }


                //ClimbAnimation.SetFloat("YMovement", Mathf.Abs(moveY));
                //Move player if on a ladder (allow horizontal movement)
                if (moveX == 0 && moveY == 0)
                {
                    _rb.velocity    = new Vector2(0, 0);
                    _rb.isKinematic = true;
                }
                else
                {
                    _rb.velocity    = new Vector2(moveX * runSpeed / 2f, moveY * runSpeed);
                    _rb.isKinematic = false;
                }
            }
            else
            {
                //Move player if not jumping in the air
                if (!_jump._inAir)
                {
                    _rb.velocity = new Vector2(moveX * runSpeed, _rb.velocity.y);
                }
            }
        }

        //Call flip script to flip the character's sprite
        if (moveX > 0)
        {
            _flipScript.FlipSprite(false);
        }
        else if (moveX < 0)
        {
            _flipScript.FlipSprite(true);
        }
    }