示例#1
0
    void Update()
    {
        if (Input.GetButtonDown("Change Perspective"))
        {
            switch (PlayerPrefs.GetInt("Perspective"))
            {
            case 1:
                PlayerPrefs.SetInt("Perspective", 3);
                break;

            case 3:
                PlayerPrefs.SetInt("Perspective", 1);
                break;
            }
        }
        float frictionJoystick = Input.GetAxis("FrictionJoystick");

        if (Input.GetButton("Friction") || frictionJoystick > 0)
        {
            Motor.DeactivateFriction();
        }
        else // if (Input.GetButtonUp("Friction") || frictionJoystick <= 0)
        {
            Motor.ActivateFriction();
        }

        //Boost gravity?
        if (Input.GetButton("Boost Gravity"))
        {
            Motor.ActivateGravityBoost();
        }
        else
        {
            Motor.DeactivateGravityBoost();
        }

        if (Input.GetButton("Scope"))
        {
            camera.fieldOfView = 10f;
        }
        else
        {
            camera.fieldOfView = 60f;
        }


        //Move player
        xAxis = Input.GetAxisRaw("Horizontal");
        zAxis = Input.GetAxisRaw("Vertical");
        Vector3 MovX = transform.right * xAxis;
        Vector3 MovZ = transform.forward * zAxis;
        Vector3 mov  = (MovX + MovZ).normalized * acceleration;

        Motor.Move(mov);

        //Rotate around the y axis
        yRotation = Input.GetAxisRaw("Mouse X");
        Vector3 rot = new Vector3(0f, yRotation, 0f) * PlayerPrefs.GetFloat("LookSensitivity");

        Motor.Rotate(rot);

        //Rotate camera around the y axis
        xRotation = Input.GetAxisRaw("Mouse Y");
        float cameraRot = xRotation * PlayerPrefs.GetFloat("LookSensitivity");

        Motor.RotateCamera(cameraRot);


        //Jetpack
        if (Input.GetButton("Jump"))
        {
            Motor.jetpackForce = JetpackForce;
            Motor.ActivateJetpack();
        }
        else
        {
            Motor.DeactivateJetpack();
        }
    }