0
\$\begingroup\$

I am developing an FPS Offline Multiplayer Game.

In my game the player rotates using mouse input.

I want to rotate using Touch input.Touch to Swipe screen and player can rotate or Camera will be same.

This is my MouseLook Script

public class FPSMouseLook : MonoBehaviour {

public enum RotationAxes{ MouseXAndY, MouseX, MouseY }
public RotationAxes axes = RotationAxes.MouseXAndY;
public float sensitivity = 4;
public float aimSensitivity = 2;

[HideInInspector]
public float sensitivityX = 15;
[HideInInspector]
public float sensitivityY = 15;
//float minimumX = -360;
//float maximumX = 360;

public float minimumY = -80;
public float maximumY = 80;

float rotationY = 0;


[HideInInspector]
public float currentSensitivity;


void Update (){

        if (Time.timeScale < 0.01f)
            return;
        if (axes == RotationAxes.MouseXAndY) {
            float rotationX = transform.localEulerAngles.y + Input.GetAxis ("Mouse X") * sensitivityX;

            rotationY += Input.GetAxis ("Mouse Y") * sensitivityY;
            rotationY = Mathf.Clamp (rotationY, minimumY, maximumY);

            transform.localEulerAngles = new Vector3 (-rotationY, rotationX, 0);
        } else if (axes == RotationAxes.MouseX) {
            transform.Rotate (0, Input.GetAxis ("Mouse X") * sensitivityX, 0);
        } else {
            rotationY += Input.GetAxis ("Mouse Y") * sensitivityY;
            rotationY = Mathf.Clamp (rotationY, minimumY, maximumY);

            transform.localEulerAngles = new Vector3 (-rotationY, transform.localEulerAngles.y, 0);
        }


        sensitivityX = currentSensitivity;
        sensitivityY = currentSensitivity;

}

public void Recoil(float amount){
    rotationY += amount;
}
}

I want to convert this into Touch input when touch to screen and swipe the finger then rotate player.

I tried doing this but it's didn't work for me. if anyone knows how to use this script based on Touch Input then it's really helpful to me. Thank in Advance

\$\endgroup\$
1
  • \$\begingroup\$ This question would be more clear if it explained in what specific way this script "didn't work for me." What were the results, and how did they differ from the desired outcome? How did you configure the script and camera in the Unity inspector? \$\endgroup\$ – DMGregory Nov 8 '18 at 8:17
0
\$\begingroup\$

hello i used this asset here is asset on asset store of fully implemented multiplayer game in unity https://www.youtube.com/watch?v=bsbdxnqh-rc https://www.assetstore.unity3d.com/en/#!/content/81698 see if it can help, just enable mobile input from the editor and create a built

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.