void Awake()
    {
        player = this;
        rb     = GetComponent <Rigidbody>();

        colliders = GetComponents <BoxCollider>();

        health       = startHealth;
        shield       = startShield;
        speedSetting = SpeedSetting.Idle;
    }
    public static void UpdateCurrentSpeed(SpeedSetting ss)
    {
        float speed = 0f;

        switch (ss)
        {
        case SpeedSetting.Full:
            speed = 1f;
            break;

        case SpeedSetting.ThreeQuarters:
            speed = .75f;
            break;

        case SpeedSetting.Half:
            speed = .5f;
            break;

        case SpeedSetting.Silent:
            speed = .25f;
            break;

        case SpeedSetting.Match:
            //find lowest max speed, and use that as direct value
            speed = Mathf.Infinity;

            for (int i = 0; i < _selectedShips.Count; i++)
            {
                if (_selectedShips[i].GetVital(VitalType.MovementSpeed).max < speed)
                {
                    speed = _selectedShips[i].GetVital(VitalType.MovementSpeed).max;
                }
            }

            break;

        default:
            speed = -1f;
            break;
        }

        for (int i = 0; i < _selectedShips.Count; i++)
        {
            if (ss == SpeedSetting.Match)
            {
                _selectedShips[i].SetCurrentSpeed(speed);
            }
            else
            {
                _selectedShips[i].UpdateCurrentSpeed(speed);
            }
        }
    }
Beispiel #3
0
    private void GetInput()
    {
        // If the player can't move then there's no point in getting any input.
        if (!canMove)
        {
            return;
        }

        // Gets vertical and horizontal input as 0-1 values then assigns them to direction.
        float xAxis = Input.GetAxis("Horizontal");
        float yAxis = Input.GetAxis("Vertical");

        this.direction = new Vector3(xAxis, 0, yAxis);

        // If shift is down then speedSetting is set to half, slowing the player; otherwise speed is at full.
        bool shiftIsdown = Input.GetKey(KeyCode.LeftShift);

        speedSetting = shiftIsdown == true ? SpeedSetting.half : SpeedSetting.full;
    }
    private void Update()
    {
        // Inputs
        stickInput     = new Vector2(Input.GetAxis("Pitch"), Input.GetAxis("Yaw"));
        dPadHorizontal = Input.GetAxis("DpadHorizontal");
        dPadVertical   = Input.GetAxis("DpadVertical");
        xButton        = Input.GetButton("X");

        if (!xButton)
        {
            if (dPadHorizontal > 0)
            {
                transform.Translate(Vector3.right * strafeSpeed);
            }
            else if (dPadHorizontal < 0)
            {
                transform.Translate(-Vector3.right * strafeSpeed);
            }

            if (dPadVertical > 0)
            {
                transform.Translate(-Vector3.down * strafeSpeed);
            }
            else if (dPadVertical < 0)
            {
                transform.Translate(Vector3.down * strafeSpeed);
            }
        }

        if (Input.GetButtonDown("AButton"))
        {
            if (speedSetting == SpeedSetting.Idle || speedSetting == SpeedSetting.Reverse)
            {
                speedSetting = SpeedSetting.Slow;
            }
            else if (speedSetting == SpeedSetting.Slow)
            {
                speedSetting = SpeedSetting.Fast;
            }
            else
            {
                speedSetting = SpeedSetting.Slow;
            }
        }

        if (Input.GetButtonDown("BButton"))
        {
            if (speedSetting == SpeedSetting.Idle)
            {
                speedSetting = SpeedSetting.Reverse;
            }
            else
            {
                speedSetting = SpeedSetting.Idle;
            }
        }

        // Switch between rolling and camera
        if (Input.GetButton("CameraSwitch"))
        {
            if (rolling)
            {
                rolling = false;
            }
            else
            {
                rolling = true;
            }
        }

        //Shield recharge
        if (shieldTimer < Time.timeSinceLevelLoad && shield < startShield)
        {
            float newAmount = shield + (Time.deltaTime * rechargeRate);

            if (newAmount < startShield)
            {
                shield = newAmount;
            }
            else
            {
                shield = startShield;
            }
        }

        if (remainingDash == 0)
        {
            dashLeft  = Input.GetButtonDown("DashLeft");
            dashRight = Input.GetButtonDown("DashRight");
        }
    }
Beispiel #5
0
 public void SetSpeedAndAcceleration(MotorSelection motors, SpeedSetting speed, Acceleration acceleration)
 {
     lock (this)
     {
         SendCommand(new byte[] { (byte)RNCommands.SetSpeedAndAcceleration, (byte)motors, (byte)speed, (byte)acceleration });
     }
 }