Question by
Angeryuu · Feb 20, 2019 at 06:14 PM ·
rotate objectworldspacemouse-drag
Rotate Object On Mouse Drag clicking on world space
Hi,
I'm trying to rotate an object when you click and drag on the screen. I have this now:
float rotSpeed;
// Start is called before the first frame update
void Start()
{
rotSpeed = 20;
}
// Update is called once per frame
void Update()
{
}
void OnMouseDrag()
{
float rotX = Input.GetAxis("Mouse X") * rotSpeed * Mathf.Deg2Rad;
transform.RotateAround(Vector3.up, -rotX);
}
It works fine and it does what I want, but it works only when you click on the object's box collider. I want that it also rotates when you click and drag on the world space. I see no explanations of how to do this correctly.
Thanks in advance.
Comment