コード例 #1
0
    /// <summary>
    /// Listens for input related to movement of the player
    /// </summary>
    private void Move()
    {
        // Ensure that the rigidbody never spins
        this.Rigidbody.angularVelocity = Vector3.zero;

        float thrustAxis = Input.GetAxis("ThrustAxis");
        float brakeAxis  = Input.GetAxis("BrakeAxis");

        if (Input.GetButtonDown("Thrust") || (previousThrustAxis == 0 && thrustAxis > 0))
        {
            movement.OnPropulsionStart();
            lightToggle.OnPropulsionStart();
            this.ChangeColor(probeColorOn, true, 0);
        }

        if (Input.GetButton("Thrust"))
        {
            movement.Propulse(-massEjectionTransform.up);
        }

        if (thrustAxis != 0)
        {
            // Propulse in the direction of the left stick (opposite to the rear of the probe)
            movement.Propulse(-massEjectionTransform.up, thrustAxis);
        }

        if (Input.GetButtonUp("Thrust") || (previousThrustAxis > 0 && thrustAxis == 0))
        {
            movement.OnPropulsionEnd();
            lightToggle.OnPropulsionEnd();
            if (!lightToggle.LightButtonPressed)
            {
                this.ChangeColor(probeColorOff, true, 0);
            }
        }

        // Brake
        if (Input.GetButton("Brake"))
        {
            movement.Brake(1);
        }
        if (brakeAxis != 0)
        {
            movement.Brake(brakeAxis);
        }

        if (isDead)
        {
            // Slow down gravity;
            Rigidbody.AddForce(Vector3.up * 20, ForceMode.Force);
        }

        // Makes the character follow the left stick's rotation
        movement.FollowLeftStickRotation();

        // Ensure that the rigidbody never spins
        this.Rigidbody.angularVelocity = Vector3.zero;

        previousThrustAxis = thrustAxis;
    }
コード例 #2
0
    /// <summary>
    /// Listens for input related to movement of the player
    /// </summary>
    private void MoveControlListener()
    {
        if (isDead)
        {
            // Slow down gravity;
            Rigidbody.AddForce(Vector3.up * 20, ForceMode.Force);
            return;
        }

        SetPlayerDrag();
        SetPlayerVelocity();

        float thrustAxis = Input.GetAxis("ThrustAxis");
        float brakeAxis  = Input.GetAxis("BrakeAxis");

        if (Input.GetButtonDown("Thrust") || (movementBean.PreviousThrustAxis == 0 && thrustAxis > 0))
        {
            movement.OnPropulsionStart();
            lightToggle.OnPropulsionStart();
        }

        if (Input.GetButtonUp("Thrust") || (movementBean.PreviousThrustAxis > 0 && thrustAxis == 0))
        {
            movement.OnPropulsionEnd();
            lightToggle.OnPropulsionEnd();
        }

        if (Input.GetButton("Thrust"))
        {
            movement.Propulse(-movementBean.MassEjectionTransform.up);
        }

        // Brake
        if (Input.GetButton("Brake"))
        {
            movement.Brake(1);
        }

        // Propulse in the direction of the left stick (opposite to the rear of the probe)
        if (thrustAxis != 0)
        {
            movement.Propulse(-movementBean.MassEjectionTransform.up, thrustAxis);
        }

        if (brakeAxis != 0)
        {
            movement.Brake(brakeAxis);
        }

        // Makes the character follow the left stick's rotation
        movement.FollowLeftStickRotation();
        movementBean.PreviousThrustAxis = thrustAxis;
    }