Beispiel #1
0
    void handleMenuInput()
    {
        float h = Input.GetAxisRaw("Vertical");

        if (hostCode.enabled)
        {
            h = 0;
        }
        float yaxis         = ControlInputWrapper.GetAxis(ControlInputWrapper.Axis.LeftStickY);
        int   size          = menu.Length;
        int   t             = currentSelection;
        int   nextSelection = t;

        if (h != 0 && canMove)
        {
            canMove = false;
            if (h < 0)
            {
                nextSelection = (currentSelection + 1);
                if (nextSelection > size - 1)
                {
                    nextSelection = 0;
                }
            }
            else if (h > 0)
            {
                nextSelection = (currentSelection - 1);
                if (nextSelection < 0)
                {
                    nextSelection = size - 1;
                }
            }
        }
        else if (h == 0)
        {
            canMove = true;
        }

        if (t != nextSelection)
        {
            oldSelection = t;
            hoverOption(nextSelection);
        }

        //handles selections
        if (Input.GetKeyUp("space") || Input.GetKeyUp("return") || ControlInputWrapper.GetButton(ControlInputWrapper.Buttons.RightBumper))
        {
            if (canSelect)
            {
                handleSelection(menu[currentSelection].name);
                canSelect = false;
            }
        }
        else
        {
            canSelect = true;
        }
    }
    void Update()
    {
        if (ControlInputWrapper.GetButton(ControlInputWrapper.Buttons.A))
        {
            Debug.Log("A");
        }
        if (isPlayer)
        {
            h = Input.GetAxisRaw("Horizontal");
            v = Input.GetAxisRaw("Vertical");
            float xaxis = ControlInputWrapper.GetAxis(ControlInputWrapper.Axis.LeftStickX);
            float yaxis = ControlInputWrapper.GetAxis(ControlInputWrapper.Axis.LeftStickY);
            if (h == 0 && v == 0)
            {
                if (Mathf.Abs(xaxis) > 0.5f)
                {
                    h = Mathf.Max(Mathf.Min(xaxis, 1f), -1f);
                }
                else
                {
                    h = 0;
                }
                if (Mathf.Abs(yaxis) > 0.5f)
                {
                    v = -Mathf.Max(Mathf.Min(yaxis, 1f), -1f);
                }
                else
                {
                    v = 0;
                }
            }

            if (Input.GetKey("space") || ControlInputWrapper.GetButton(ControlInputWrapper.Buttons.RightBumper))
            {
                shooting = true;
            }
            else
            {
                shooting = false;
            }

            if (move.GetDead())
            {
                h        = 0;
                v        = 0;
                shooting = false;
            }

            if ((h != oldH || v != oldV) && moveCountdown < 1)
            {
                oldH          = h;
                oldV          = v;
                needsUpdate   = true;
                moveCountdown = 4;
            }
            else
            {
                moveCountdown -= 1;
            }

            if (oldShooting != shooting)
            {
                needsUpdate = true;
                oldShooting = shooting;
            }

            if (Input.GetKey("q") || (ControlInputWrapper.GetButton(ControlInputWrapper.Buttons.Y)))
            {
                reviveBtn = true;
            }
            else
            {
                reviveBtn = false;
            }
        }

        shooter.setShooting(shooting);

        //this should be somewhere else

        /*CapsuleCollider cc = GetComponent<CapsuleCollider> ();
         * if (shooting) {
         *      h = 0;
         *      v = 0;
         *      cc.height = ccHeight * 0.8f;
         * } else {
         *      cc.height = ccHeight;
         * }*/

        move.Move(h, v);
        Turning();
        movement = move.getMove();

        Vector2 spdir = DetermineDir(h, v);

        move.backwards = spdir.x < 0;
        if (spdir.x == 0)
        {
            spdir.x = 0.05f;
        }
        if (!move.GetDead())
        {
            anim.SetFloat("SpeedAmnt", (spdir.x));
            anim.SetFloat("Direction", spdir.y, .25f, Time.deltaTime);
            anim.SetBool("Shooting", shooting);
        }
    }