예제 #1
0
    // FixedUpdate is called at constant intervals
    void FixedUpdate()
    {
        if (is_dying)
        {
            dying_counter -= Time.deltaTime;
            rb.velocity    = new Vector3(0, 0);
            if (dying_counter < 0)
            {
                reset_on_death();
            }
            else
            {
                return;
            }
        }
        ;

        /*** Player motion ***/
        if (input_module.is_moving())
        {
            //horizontal movement
            transform.localPosition += new Vector3(input_module.get_movement() * (speed * Time.deltaTime), 0);               //control movement speed
            player_renderer.flipX    = input_module.get_movement() < 0 ? true : false;
            player_animator.SetBool("is_walking", true);

            fx_walking = true;
        }
        else
        {
            player_animator.SetBool("is_walking", false);
            fx_walking = false;
        }

        bool _jump = input_module.get_jump();

        if (is_on_ground)
        {
            if (!old_ground)
            {
                //just landed
                jumped = false;
                player_animator.SetBool("is_jumping", false);
                player_animator.SetBool("is_falling", false);
                fx_walking = true;
            }

            //perform jump
            if (!jumped && _jump)
            {
                jumped       = true;
                is_on_ground = false; old_ground = true;
                Vector3 up = new Vector3(0, 1);
                rb.AddForce(jump_force * up);
            }
        }
        if (!is_on_ground)
        {
            fx_walking = false;
            if (old_ground)
            {
                //just jumped or fell
                if (jumped)
                {
                    //just jumped
                    player_animator.SetBool("is_jumping", true);
                }
                else
                {
                    //just fell
                    player_animator.SetBool("is_falling", true);
                }
            }

            if (jumped && rb.velocity.y < 0)
            {
                //change from jumping to falling
                jumped = false;
                player_animator.SetBool("is_falling", true);
            }
        }
        if (in_vines && input_module.is_pressing_climb_button())
        {
            is_climbing = true; player_animator.SetBool("is_climbing", true);
        }
        if (is_climbing)
        {
            rb.gravityScale = 0.0f;
            //move
            int c = input_module.get_climbing_movement();
            rb.velocity = new Vector3(0, c * climb_speed * Time.deltaTime);
            player_animator.SetBool("is_climbing_idle", c == 0);
            fx_climbing = c != 0;
        }
        else
        {
            rb.gravityScale = 1.0f;
            player_animator.SetBool("is_climbing", false);
            fx_climbing = false;
        }

        old_ground = is_on_ground;

        //signs
        if (in_sign && !reading_sign)
        {
            reading_sign = input_module.is_pressing_enter();
            if (reading_sign)
            {
                sign_popup.SetActive(true);
                sign_text_crawl.ShowText(position_to_string_text(transform.position));
            }
        }
        sign_prompt.enabled = in_sign && !reading_sign;         //display sign prompt

        //display sign text
        sign_popup.SetActive(in_sign && reading_sign);

        //fx
        if (fx_climbing)
        {
            if (!fx_source.loop || fx_source.clip != climbing_fx)
            {
                fx_source.loop = true;
                fx_source.clip = climbing_fx;
                fx_source.Play();
            }
        }
        else if (fx_walking)
        {
            if (!fx_source.loop || fx_source.clip != walking_fx)
            {
                fx_source.loop = true;
                fx_source.clip = walking_fx;
                fx_source.Play();
            }
        }
        else
        {
            fx_source.loop = false;
        }
    }