Hello all, newbie at Unity and these forums, hoping someone can help!
So yesterday this code worked just fine - currentMousePos is updated while a mousebutton is held down:
public void PanCamera()
{
currentMousePos = cam.ScreenToWorldPoint(Input.mousePosition);
mouseCamAdjust = currentMousePos.x - startMousePos.x;
Debug.Log("start:" + startMousePos + "current:" + currentMousePos + "adjust:" + mouseCamAdjust);
//translate cam, but only on x axis
//multiply by 2 to speed up the scrolling so you dont have to move mouse too much
cam.transform.position += new Vector3(mouseCamAdjust * 2, 0f, 0f);
}
Today I upgraded from 2019.4.17f1 to 2020.2.1f1 and for some reason the panning seems to be broken. I’ve not changed any code. The debug string above is appearing in my console, so we’re entering this function, it just seems to not ‘notice’ any difference between the start position and current position - i.e. they always seem to be the same.
Even more bizarrely, while debugging and leaving the game running in play mode, if I edit the script and save, sometimes it just suddenly starts to work. Very strange!
I guess it could be because it’s running so quick that the start/current mouse pos end up being the same, but it’s unusual that it worked yesterday but now doesn’t.
Anyhoo - any pointers on what might have happened, or an alternative way to achieve the same result would be appreciated.