Answer the question
In order to leave comments, you need to log in
What causes sticking?
void Update(){
MoveCamera();
}
public bool IsPointerOverUIObject() {
PointerEventData ep = new PointerEventData(EventSystem.current);
ep.position = new Vector2(Input.mousePosition.x, Input.mousePosition.y);
List<RaycastResult> results = new List<RaycastResult>();
EventSystem.current.RaycastAll(ep, results);
return results.Count > 0;
}
private void MoveCamera(){
if(!IsPointerOverUIObject()){
if(Input.GetMouseButtonDown(0)){ CurrentPositionCamera = MainCamera.ScreenToWorldPoint(Input.mousePosition); }
if(Input.GetMouseButton(0)){ VerifyBoundCamera(); }else{ CameraMove = false; }
if(Input.GetMouseButtonUp(0)){ CameraMove = false; }
}else{ CameraMove = false; CurrentPositionCamera = MainCamera.ScreenToWorldPoint(Input.mousePosition); }
}
}
private void VerifyBoundCamera(){
PosInputMouse = MainCamera.ScreenToWorldPoint(Input.mousePosition);
DifferencePositionCamera = CurrentPositionCamera - PosInputMouse;
if(MainCamera.transform.position.y + DifferencePositionCamera.y > MaxY){
DifferencePositionCamera.y = 0f;
CurrentPositionCamera = new Vector3(CurrentPositionCamera.x, PosInputMouse.y, -1f);
}else if(MainCamera.transform.position.y + DifferencePositionCamera.y < MinY){
DifferencePositionCamera.y = 0f;
CurrentPositionCamera = new Vector3(CurrentPositionCamera.x, PosInputMouse.y, -1f);
}
if(MainCamera.transform.position.x + DifferencePositionCamera.x > MaxX){
DifferencePositionCamera.x = 0f;
CurrentPositionCamera = new Vector3(PosInputMouse.x, CurrentPositionCamera.y, -1f);
}else if(MainCamera.transform.position.x + DifferencePositionCamera.x < MinX){
DifferencePositionCamera.x = 0f;
CurrentPositionCamera = new Vector3(PosInputMouse.x, CurrentPositionCamera.y, -1f);
}
if(DifferencePositionCamera != PrevPositionCamera){
MainCamera.transform.position += DifferencePositionCamera;
PrevPositionCamera = DifferencePositionCamera;
CameraMove = true;
}else CameraMove = false;
}
Answer the question
In order to leave comments, you need to log in
Didn't check the entire script, but noticed the following:
1. Click-once checks are not next to each other. Those. after a single press test, a long press test is started.
2. When checking for a long press, a method is launched that, until it has fully worked out, will continue to move
3. The gag can be caused by this. Those. there is an invalid boolean condition in the method fired on the hit test that keeps moving.
Solution:
1. Put Down and Up checks next to each other
2. Comment out Down and Up and check how
getButton works 3. If getButton works fine when commenting Up and Down, look for reasons
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question