// Update is called once per frame
        void Update()
        {
            //get player input for motion
            Vector3 motionInput = Sinput.GetVector("Horizontal", "", "Vertical", playerSlot);

            //we want to move like, three times as much as this
            motionInput *= 3f;

            //gravity
            yMotion      -= Time.deltaTime * 10f;
            motionInput.y = yMotion;

            //move our character controller now
            characterController.Move(motionInput * Time.deltaTime);

            if (characterController.isGrounded)
            {
                yMotion = -0.05f;

                if (Sinput.GetButtonDown("Jump", playerSlot))
                {
                    yMotion = 5f;
                }
            }
        }
    void Update()
    {
        if (PlayerNumber == 1)
        {
            _playerAxis = Sinput.GetVector("Horizontal", "Vertical", _playerSlot1) * Time.deltaTime * 50f;
        }

        if (PlayerNumber == 2)
        {
            _playerAxis = new Vector2(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical") * Time.deltaTime * 50f);
            //_playerAxis = Sinput.GetVector("Horizontal", "Vertical", _playerSlot2) * Time.deltaTime * 50f;
        }
        if (!_forceAdded)
        {
            _forceAdded = true;
            _fishRigidbody.AddForce(_playerAxis, ForceMode2D.Impulse);
            _forceAdded = false;
        }
        ClampingVelocity(_zRot);
    }
    void CheckInput()
    {
        for (int n = 0; n < buttons.Length; n++)
        {
            if (Sinput.GetButtonDown(buttons[n].name))
            {
                buttons[n].SetState(true);
                buttons[n].events.Pressed?.Invoke();
            }

            if (Sinput.GetButtonUp(buttons[n].name))
            {
                buttons[n].SetState(false);
                buttons[n].events.Released?.Invoke();
            }
        }

        for (int n = 0; n < axes.Length; n++)
        {
            bool state = false;
            for (int i = 0; i < axes[n].names.Length; i++)
            {
                float value = Sinput.GetAxis(axes[n].names[i]);
                state = Mathf.Abs(value) > 0f;
                if (axes[n].sendWhenZeroToo || state)
                {
                    axes[n].AxisValue?.Invoke(value);
                    break;
                }
            }

            bool prevState = axes[n].isPressed;
            axes[n].SetState(state);

            if (state)
            {
                if (!prevState)
                {
                    axes[n].events.Pressed?.Invoke();
                }
            }
            else if (prevState)
            {
                axes[n].events.Released?.Invoke();
            }
        }

        for (int n = 0; n < joysticks.Length; n++)
        {
            bool state = false;
            for (int i = 0; i < joysticks[n].names.Length; i++)
            {
                Vector2 value = Sinput.GetVector(joysticks[n].names[i].x, joysticks[n].names[i].y,
                                                 joysticks[n].normalizationMode != NormalizationMode.NotNormalize);
                state = value.sqrMagnitude > 0f;

                if (state && (joysticks[n].normalizationMode == NormalizationMode.NormalizeWithoutPithagoras))
                {
                    if (Mathf.Abs(value.x) > Mathf.Abs(value.y))
                    {
                        value.x = Mathf.Sign(value.x);
                    }
                    else if (Mathf.Abs(value.x) < Mathf.Abs(value.y))
                    {
                        value.y = Mathf.Sign(value.y);
                    }
                    else
                    {
                        value.x = Mathf.Sign(value.x); value.y = Mathf.Sign(value.y);
                    }
                }

                if (joysticks[n].sendWhenZeroToo || state)
                {
                    joysticks[n].JoystickValue?.Invoke(value);
                    joysticks[n].JoystickMagnitude?.Invoke(value.magnitude);
                    break;
                }
            }

            bool prevState = joysticks[n].isPressed;
            joysticks[n].SetState(state);

            if (state)
            {
                if (!prevState)
                {
                    joysticks[n].events.Pressed?.Invoke();
                }
            }
            else if (prevState)
            {
                joysticks[n].events.Released?.Invoke();
            }
        }

        for (int n = 0; n < buttonStates.Length; n++)
        {
            bool state = true;
            foreach (SButtonState button in buttonStates[n].buttonsState)
            {
                if (Sinput.GetButton(button.name) != button.state)
                {
                    state = false;
                    break;
                }
            }

            bool prevState = buttonStates[n].isPressed;
            buttonStates[n].SetState(state);

            if (state)
            {
                if (!prevState)
                {
                    buttonStates[n].events.Pressed?.Invoke();
                }
            }
            else if (prevState)
            {
                buttonStates[n].events.Released?.Invoke();
            }
        }
    }
示例#4
0
        // Update is called once per frame
        void Update()
        {
            //get player input for motion
            Vector3 motionInput = Sinput.GetVector("Horizontal", "", "Vertical", playerSlot);

            //we want to move like, three times as much as this
            motionInput *= 3f;

            //gravity
            yMotion      -= Time.deltaTime * 10f;
            motionInput.y = yMotion;

            //move our character controller now
            characterController.Move(motionInput * Time.deltaTime);

            //landing/jumping
            if (characterController.isGrounded)
            {
                yMotion = -0.05f;

                if (Sinput.GetButtonDown("Jump", playerSlot))
                {
                    //we pressed jump while on the ground, so we jump!
                    yMotion = 5f;
                }
            }

            //aiming
            Vector3 aimDir = Vector3.zero;

            aimDir.x = Sinput.GetAxisRaw("Horizontal", playerSlot);
            aimDir.z = Sinput.GetAxisRaw("Vertical", playerSlot);
            if (aimDir.magnitude > 0.4f)
            {
                //inputs are strong enough, lets look in the aim direction
                lookDirection = aimDir.normalized;
                Quaternion fromRotation = transform.rotation;
                transform.LookAt(transform.position + lookDirection);
                transform.rotation = Quaternion.Slerp(fromRotation, transform.rotation, Time.deltaTime * 10f);
            }
            //make sure our display text always faces the same way
            playerSlotDisplay.transform.eulerAngles = Vector3.zero;


            //shooting
            bulletCooldown -= Time.deltaTime;
            if (Sinput.GetButton("Fire1", playerSlot) && bulletCooldown <= 0f)
            {
                bulletCooldown = 0.2f;
                GameObject newBullet = (GameObject)GameObject.Instantiate(bulletPrefab);
                newBullet.transform.position = gunTransform.position;
                newBullet.transform.rotation = gunTransform.rotation;
                newBullet.GetComponent <BulletScript>().moveDir = gunTransform.forward;
            }
            if (Sinput.GetButton("Fire2", playerSlot) && bulletCooldown <= 0f)
            {
                bulletCooldown = 0.05f;
                GameObject newBullet = (GameObject)GameObject.Instantiate(bulletPrefab);
                newBullet.transform.position   = gunTransform.position;
                newBullet.transform.rotation   = gunTransform.rotation;
                newBullet.transform.localScale = Vector3.one * 0.3f;
                newBullet.GetComponent <BulletScript>().moveDir   = gunTransform.forward;
                newBullet.GetComponent <BulletScript>().moveSpeed = 30f;
                newBullet.GetComponent <BulletScript>().life      = 0.33f;
            }
        }