Problems with mobile camera rotation
I'm building a 360 tour in unity, and using a very elegant "click to drag" script for the camera, and clickable hotspots.
//MouseDrag
using UnityEngine;
using UnityEngine.UI;
public class StreetViewCamera : MonoBehaviour
{
public float speed = 1.5f;
private float X;
private float Y;
void Update()
{
if (Input.GetKey(KeyCode.Mouse0))
{
transform.Rotate(new Vector3(Input.GetAxis("Mouse Y") * speed, -Input.GetAxis("Mouse X") * speed, 0));
X = transform.rotation.eulerAngles.x;
Y = transform.rotation.eulerAngles.y;
transform.rotation = Quaternion.Euler(X, Y, 0);
}
}
}
On PC this works perfectly. On mobile, however, when you tap your finger anywhere, the camera automatically recenters itself based on an some arbitrary position which you can then drag around from. How can I prevent it from changing orientation whenever the screen is clicked, or center the change on the current view?
Current version: https://infinatummedia.com/reality/Webgl/OptimizedTest/
Your answer
![](https://koobas.hobune.stream/wayback/20220613003300im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Best way to spawn objects randomly on only x-axis on Mobile 0 Answers
Performance much worse on LWRP than on BuiltIn Pipeline 0 Answers
How to stop the character from rotating around? 1 Answer
NullReferenceException on a GameObject holding the main scene camera as the parent 1 Answer
Can i make my camera rotate towards the object or any point for VR? 0 Answers