コード例 #1
0
        // Update is called once per frame
        void Update()
        {
            //grounded = Physics2D.Linecast(transform.position, groundCheck.position, 1 << LayerMask.NameToLayer("Ground"));
            if (canInteract && !dialogueEngine.IsTalking())
            {
                talkIndicator.GetComponent <Renderer>().enabled = true;
            }
            else
            {
                talkIndicator.GetComponent <Renderer>().enabled = false;
            }

            // Cannot receive inputs if we are talking to someone
            if (!frozen && (!dialogueEngine || !dialogueEngine.IsTalking()))
            {
                horiz = Input.GetAxis("Horizontal");
                // Jumping
                if (Input.GetButtonDown("Jump") && grounded)
                {
                    jump     = true;
                    grounded = false;
                }

                // Crouching - Can only crouch if we have beaten or are currently playing the ostrich game
                if (Input.GetButton("Hide") && grounded && (GlobalState.instance.ostrichGameComplete || SceneManager.GetActiveScene().name == "Ostrich_Game"))
                {
                    animator.SetInteger("Fish_anim", 2);
                    // Walking
                }
                else if (!grounded)
                {
                    animator.SetInteger("Fish_anim", 3);
                    Vector3 pos = transform.position;
                    pos.x += speed * horiz;
                    transform.position = pos;
                }
                else if (Input.GetAxis("Horizontal") != 0)
                {
                    animator.SetInteger("Fish_anim", 1);
                    Vector3 pos = transform.position;
                    pos.x += speed * horiz;
                    transform.position = pos;
                    // Posing
                }
                else if (Input.GetAxis("Pose_vert") > 0 && GlobalState.instance.peacockGameComplete)
                {
                    animator.SetInteger("Fish_anim", 5);
                    print("pose");
                }
                else if (Input.GetAxis("Pose_vert") < 0 && GlobalState.instance.peacockGameComplete)
                {
                    animator.SetInteger("Fish_anim", 6);
                    print("pose");
                }
                else if (Input.GetAxis("Pose_horiz") > 0 && GlobalState.instance.peacockGameComplete)
                {
                    animator.SetInteger("Fish_anim", 7);
                    print("pose");
                }
                else if (Input.GetAxis("Pose_horiz") < 0 && GlobalState.instance.peacockGameComplete)
                {
                    animator.SetInteger("Fish_anim", 8);
                    print("pose");
                    // Idle
                }
                else
                {
                    animator.SetInteger("Fish_anim", 0);
                }

                // Facing
                if (Input.GetAxis("Horizontal") >= 0)
                {
                    animator.SetInteger("Direction", 1);
                }
                else
                {
                    animator.SetInteger("Direction", 0);
                }

                // Interaction mechanics
                if (Input.GetButtonDown("Interact") && canInteract)
                {
                    // If the object is an Actor, talk to it
                    Actor npc = interactor.GetComponent <Actor>();
                    if (npc)
                    {
                        // Turn on the idle animation
                        animator.SetInteger("Fish_anim", 0);

                        // Special case for the seagull game
                        if (SceneManager.GetActiveScene().name == "Seagull_Game")
                        {
                            GlobalState.instance.seagullGameComplete = true;
                        }

                        dialogueEngine.Talk(npc);
                    }
                }
            }
            else
            {
                // If we are talking, progress the dialogue when the Input or Jump buttons are pressed
                if (Input.GetButtonDown("Interact") || Input.GetButtonDown("Jump"))
                {
                    dialogueEngine.OnButtonClick();
                }
            }

            if (jump)
            {
                // Add a vertical force to the player.
                GetComponent <Rigidbody2D>().AddForce(new Vector2(0f, jumpForce));

                // Make sure the player can't jump again until the jump conditions from Update are satisfied.
                jump = false;
            }
        }
コード例 #2
0
        // Update is called once per frame
        void Update()
        {
            //grounded = Physics2D.Linecast(transform.position, groundCheck.position, 1 << LayerMask.NameToLayer("Ground"));
            animator.SetInteger("Direction", 1);
            // Cannot receive inputs if we are talking to someone
            if (!dialogueEngine || !dialogueEngine.IsTalking())
            {
                if (leave_as_false && Input.GetAxis("Horizontal") < 0)
                {
                    horiz = 0;
                }
                else if (OstrichMG_controller.start)
                {
                    horiz = Input.GetAxis("Horizontal");
                }
                // Jumping

                /*if (Input.GetButtonDown ("Jump") && grounded) {
                 *              jump = true;
                 *              grounded = false;
                 * }*/

                // Crouching
                if (Input.GetButton("Hide") && grounded)
                {
                    animator.SetInteger("Fish_anim", 2);
                    animator.SetInteger("Direction", 1);
                    // Walking
                }
                else if (Input.GetAxis("Horizontal") != 0 && !leave_as_false)
                {
                    animator.SetInteger("Fish_anim", 1);
                    animator.SetInteger("Direction", 1);
                    Vector3 pos = transform.position;
                    pos.x += speed * horiz;
                    transform.position = pos;
                    // Idle
                }
                else if (Input.GetAxis("Horizontal") > 0 && OstrichMG_controller.start)
                {
                    animator.SetInteger("Fish_anim", 1);
                    animator.SetInteger("Direction", 1);
                    Vector3 pos = transform.position;
                    pos.x += speed * horiz;
                    transform.position = pos;
                    // Idle
                }
                else
                {
                    animator.SetInteger("Fish_anim", 0);
                    animator.SetInteger("Direction", 1);
                }



                // Interaction mechanics
                if (Input.GetButtonDown("Interact") && canInteract)
                {
                    // If the object is an Actor, talk to it
                    Actor npc = interactor.GetComponent <Actor>();
                    if (npc)
                    {
                        // Turn on the idle animation
                        animator.SetInteger("Fish_anim", 0);
                        dialogueEngine.Talk(npc);
                    }
                }
            }
            else
            {
                // If we are talking, progress the dialogue when the Input or Jump buttons are pressed
                if (Input.GetButtonDown("Interact") || Input.GetButtonDown("Jump"))
                {
                    dialogueEngine.OnButtonClick();
                }
            }

            if (jump)
            {
                // Add a vertical force to the player.
                GetComponent <Rigidbody2D>().AddForce(new Vector2(0f, jumpForce));

                // Make sure the player can't jump again until the jump conditions from Update are satisfied.
                jump = false;
            }
        }