Hello, I'm trying to do a simple 2D "hand tool". I got it working but I accidentally deleted something I thought was obsolete. As it turns out, my first try was a stroke of luck, since I haven't been able to make it work again.
I experience a bug where the camera flickers when i try to drag. I'm sure I'm not the first person to do a drag script (maybe the biggest n00b tho), but i cannot find any other documentation on this. Any input would be appreciated.
//SCROLL
var camCurrent : Vector3; //static camera position
var pressedPosDif : Vector3; // difference between pressed and moved
var pressedPos: Vector3; //starting coordinates for button hold
var pressed:boolean = false; //is the button held?
//INITIATE
function Start(){
camCurrent=camera.main.transform.position;
}
//UPDATE
function Update () {
if (Input.GetMouseButtonDown(0)) {
pressedPos = (Camera.main.ScreenToWorldPoint(Input.mousePosition));
pressed = true;
mouseCheck();
}
}
function mouseCheck () {
while (pressed) {
pressedPosDif=pressedPos-(Camera.main.ScreenToWorldPoint(Input.mousePosition));
Camera.main.transform.position=camCurrent+pressedPosDif;
yield;
if (Input.GetMouseButtonUp(0)) {
camCurrent=Camera.main.transform.position;
pressed = false;
}
}
}
Why pay money when there's good free alternatives? https://www.assetstore.unity3d.com/en/#!/content/12324
– tanoshimi