This code rotates my model along its Y axis when I click and drag. I like how this code works, but it affect the whole scene window. So when I click a button on my interface, the model moves a little since it is set to rotate the model on mouse down. It looks like a glitch to my clients. I’m not sure what the best way to correct it would be except maybe to have this code function with a right mouse button drag? Is that possible? Does anyone have a suggestion for a different way to handle this maybe? Is there a different script that might do the same thing, but is contained to when you hover over the gameObject? I don’t know. Any help would be appreciated!
public class CamControl : MonoBehaviour
{
public int speed;
public int friction;
public int lerpSpeed;
private float xDeg;
private float yDeg;
private Quaternion fromRotation;
private Quaternion toRotation;
// Update is called once per frame
void Update ()
{
if(Input.GetMouseButton(0))
{
xDeg -= Input.GetAxis("Mouse X") * speed * friction;
yDeg += Input.GetAxis("Mouse Y") * speed * friction;
yDeg = Mathf.Clamp (0,0,0); //lock out to enable full spin control
fromRotation = transform.rotation;
toRotation = Quaternion.Euler(yDeg,xDeg,0);
transform.rotation = Quaternion.Lerp(fromRotation,toRotation,Time.deltaTime * lerpSpeed);
}
}
}