问题
Does any one know how to control the camera view with only a single joystick? Currently im using a joystick from the switch. Heres my current code.
public class MoveCamera : MonoBehaviour
{
public float speed = 1.0f;
Camera cameraMovement;
void Update ()
{
float xRot = speed * Input.GetAxis("JoyStickX");
float yRot = speed * Input.GetAxis("JoyStickY");
transform.Rotate(xRot, yRot, 0.0f);
}
}
回答1:
- In the editor, create an empty game object called "Pivot"
- Make your camera a child of Pivot.
- Move the camera away from Pivot, whatever distance you need.
- Now attach a script to Pivot.
Something like this :
void Update(){
float speed = 3.0f;
float xRot = speed * Input.GetAxis("Vertical");
float yRot = speed * Input.GetAxis("Horizontal");
transform.Rotate(xRot, yRot, 0.0f);
}
- Assign your camera to the camera var in the script attached to Pivot
- Now you do the messing around of the rotation
来源:https://stackoverflow.com/questions/48294739/unity-how-to-control-camera-view-using-a-single-joystick