Пример #1
0
    void Update()
    {
        Vector2 velo = r2d.velocity;

        velo.x = Input.GetAxis(whichPlayer + "Horizontal") * moveSpeed;

        if (stunIndicatorInProgress == null)
        {
            if (hatchIndicatorInProgress == null)
            {
                if (Input.GetButtonDown(whichPlayer + "Hatch") && couldHatch)
                {
                    ouHeld.transform.localPosition  = hatchPosition;
                    hatchIndicatorInProgress        = Instantiate(hatchIndicator, transform, false).GetComponent <HatchIndicator>();
                    hatchIndicatorInProgress.player = this;
                    audio.PlayOneShot(hatching);
                }
                else if (Input.GetButtonDown(whichPlayer + "Fire") && ouHeld != null)
                {
                    ouHeld.Throw((facing_left ? -1 : 1) * vrum);
                    ouHeld = null;
                    audio.PlayOneShot(shoot);
                }
            }
            else
            {
                if (Input.GetButtonUp(whichPlayer + "Hatch"))
                {
                    Destroy(hatchIndicatorInProgress.gameObject);
                    hatchIndicatorInProgress       = null;
                    ouHeld.transform.localPosition = carryPosition;
                }
            }
        }

        if (Mathf.Abs(velo.y) >= 1)   // if jumping
        {
            anim.SetBool("isJumpingRight", !facing_left);
            anim.SetBool("isJumpingLeft", facing_left);
            anim.SetBool("isWalkingLeft", false);
            anim.SetBool("isWalkingRight", false);
        }
        else
        {
            anim.SetBool("isJumpingRight", false);
            anim.SetBool("isJumpingLeft", false);

            if (velo.x != 0)
            {
                facing_left = velo.x < 0;
                anim.SetBool("isWalkingLeft", facing_left);
                anim.SetBool("isWalkingRight", !facing_left);
            }
            else
            {
                anim.SetBool("isWalkingRight", false);
                anim.SetBool("isWalkingLeft", false);
            }
        }


        // Handle pause
        if (Input.GetButtonDown("Cancel"))
        {
            //if (controlsEnabled) {
            //    freeze();
            //    Universe.TogglePause(() => defrost());
            //}
            //else {
            //    Universe.TogglePause();
            //}
        }
    }