- Home /
Question by
unity_6deBw_dYkk9DAg · Feb 15, 2020 at 11:26 AM ·
screenswipecamera movementwidthhalf
how to move camera using finger swipe by using right half of screen width,how to move camera using finger swipe in half portion of screen
/My code/
Vector3 hit_position = Vector3.zero; Vector3 current_position = Vector3.zero; Vector3 camera_position = Vector3.zero; void Update() {
if (Input.GetMouseButtonDown(0))
{
if (Input.mousePosition.x > Screen.width / 2 && Input.touchCount<2)
{
hit_position = Input.mousePosition;
camera_position = transform.position;
}
}
if (Input.GetMouseButton(0)&& Input.touchCount<2)
{
if (Input.mousePosition.x > Screen.width / 2)
{
current_position = Input.mousePosition;
LeftMouseDrag();
}
}
} void LeftMouseDrag(){
Vector3 direction = Camera.main.ScreenToWorldPoint(current_position) - Camera.main.ScreenToWorldPoint(hit_position);
Vector3 position = camera_position + direction;
transform.position = position;
},
Comment