Beispiel #1
0
    // method for user input
    private void CheckInput()
    {
        if (butcher)
        {
            if (anim.GetCurrentAnimatorStateInfo(0).normalizedTime > 1 && !anim.IsInTransition(0))
            {
                butcher = false;
                anim.SetBool("butcher", false);
            }
        }
        else if (feeding)
        {
            if (anim.GetCurrentAnimatorStateInfo(0).normalizedTime > 1 && !anim.IsInTransition(0))
            {
                feeding = false;
                photonView.RPC("SpawnFeed", PhotonTargets.MasterClient, PlaceFeed.transform.position.x, PlaceFeed.transform.position.y);
                anim.SetBool("feeding", false);
            }
        }
        else if (!InterfaceOpen())
        {
            if (!hotbar.visible)
            {
                hotbar.visible = true;
            }

            CheckHover();

            UpdateColliders();

            float moveX = Input.GetAxisRaw("Horizontal");
            float moveY = Input.GetAxisRaw("Vertical");
            moveDirection = new Vector2(moveX, moveY).normalized;

            // keyboard controls
            if (direction != 0 && Input.GetKey(KeyCode.A) && !Input.GetKey(KeyCode.D))
            {
                direction = 0;
                photonView.RPC("FlipTrue", PhotonTargets.AllBuffered);
            }

            else if (direction != 1 && Input.GetKey(KeyCode.D) && !Input.GetKey(KeyCode.A))
            {
                direction = 1;
                photonView.RPC("FlipFalse", PhotonTargets.AllBuffered);
            }

            // animation updates
            if (Mathf.Abs(rb.velocity.x) > 0.25 || Mathf.Abs(rb.velocity.y) > 0.25)
            {
                anim.SetBool("isMoving", true);
            }
            else
            {
                anim.SetBool("isMoving", false);
            }

            // spawns a chicken for testing
            if (Input.GetKeyDown(KeyCode.Alpha0))
            {
                photonView.RPC("SpawnChicken", PhotonTargets.MasterClient, transform.position.x, transform.position.y);
            }

            if (Input.GetMouseButtonDown(0))
            {
                if (!butcher && CanButcher() && !feeding)
                {
                    shake.SwingShake(direction);
                    int randSwing = Random.Range(0, 3);
                    if (randSwing == 0)
                    {
                        photonView.RPC("PlayWorldAudio", PhotonTargets.All, "swing1");
                    }
                    else if (randSwing == 1)
                    {
                        photonView.RPC("PlayWorldAudio", PhotonTargets.All, "swing2");
                    }
                    else
                    {
                        photonView.RPC("PlayWorldAudio", PhotonTargets.All, "swing3");
                    }
                    butcher = true;
                    anim.SetBool("butcher", true);
                    anim.SetBool("isMoving", false);
                }
            }
        }
        else
        {
            anim.SetBool("isMoving", false);

            if (uiManager.speechVisible && hotbar.visible)
            {
                hotbar.visible = false;
            }
            else if (uiManager.marketVisible || uiManager.auctionVisible)
            {
                hotbar.visible = true;
            }
        }
    }