private Vector3 startpoint; // startpoint
private Vector3 endpoint; // endpoint
private bool panning=false;
public float minPosX = 10;
public float maxPosX =10;
//GameObject CO;
public float minPosZ=-10;
public float maxPosZ=10;
float dist;
bool MouseUse= true;
// mainloop
void Update (){
Ray ray1 = Camera.main.ScreenPointToRay (Input.mousePosition);
Ray ray2 = Camera.main.ScreenPointToRay (Input.mousePosition);
if (Input.touchCount == 1) {
// starts here, left mousebutton is pressed down
if(Input.GetMouseButtonDown(0))
{
// make ray
startpoint = ray1.GetPoint (10) ; // Returns a point at distance units along the ray
startpoint.y = 0; // fix z to 0
panning = true;
}
// then left mousebutton is released
if(panning){
dist = Mathf.Clamp((Vector3.Distance(endpoint, startpoint)),0,1.0f);
endpoint = ray2.GetPoint (10) ; // Returns a point at distance units along the ray
endpoint.y = 0; // fix z, somehow its not always 0?
// Panning
if(dist >= 0.1f){
transform.position += startpoint-endpoint;
Vector3 pos = transform.position;
pos.x =Mathf.Clamp(pos.x, minPosX, maxPosX);
pos.z =Mathf.Clamp(pos.z, minPosZ, maxPosZ);
transform.position = pos;
}
}
if(Input.GetMouseButtonUp(0)) // release button, stop pan
{
panning = false;
}
}
if (MouseUse == true)
{
if(Input.GetMouseButtonDown(0))
{
// make ray
startpoint = ray1.GetPoint (10) ; // Returns a point at distance units along the ray
startpoint.y = 0; // fix z to 0
panning = true;
}
// then left mousebutton is released
if(panning){
dist = Mathf.Clamp((Vector3.Distance(endpoint, startpoint)),0,1.0f);
endpoint = ray2.GetPoint (10) ; // Returns a point at distance units along the ray
endpoint.y = 0; // fix z, somehow its not always 0?
// Panning
if(dist >= 0.1f){
transform.position+=startpoint-endpoint;
Vector3 pos = transform.position;
pos.x =Mathf.Clamp(pos.x, minPosX, maxPosX);
pos.z =Mathf.Clamp(pos.z, minPosZ, maxPosZ);
transform.position = pos;
}
}
if(Input.GetMouseButtonUp(0)) // release button, stop pan
{
panning = false;
}
}
}