Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void MoveCamera()
- {
- float xPos = Input.mousePosition.x;
- float yPos = Input.mousePosition.y;
- Vector3 movement = new Vector3(0,0,0);
- //horizontal movement
- if(xPos >= 0 && xPos < ResourceManager.scrollWidth)
- {
- movement.x=-Time.deltaTime*ResourceManager.scrollSpeed;
- }
- else if(xPos <= Screen.width && xPos > Screen.width - ResourceManager.scrollWidth)
- {
- movement.x=Time.deltaTime*ResourceManager.scrollSpeed;
- }
- //vertical movement
- if(yPos >= 0 && yPos < ResourceManager.scrollWidth)
- {
- movement.z=-Time.deltaTime*ResourceManager.scrollSpeed;
- }
- else if (yPos <= Screen.height && yPos > Screen.height-ResourceManager.scrollWidth)
- {
- movement.z=Time.deltaTime*ResourceManager.scrollSpeed;
- }
- //makes the movement take the rotation of the camera into account
- movement = Camera.main.transform.TransformDirection(movement);
- movement.y=0;
- //find movement direction
- Vector3 origin = Camera.main.transform.position;
- Vector3 destination = origin;
- destination.x+=movement.x;
- destination.z+=movement.z;
- //move camera if the XZ-position has changed
- if(destination!=origin)
- {
- Camera.main.transform.position = Vector3.MoveTowards(origin, destination, ResourceManager.maxCameraMoveSpeed);
- }
- //set zoom
- movement.y-=ResourceManager.zoomSpeed*Input.GetAxis("Mouse ScrollWheel");
- destination=origin;
- destination.y+=movement.y;
- destination.y=Mathf.Clamp (destination.y, ResourceManager.minCameraHeight, ResourceManager.maxCameraHeight);
- //move camera if Y-position has changed
- if(destination!=origin)
- {
- Camera.main.transform.position = destination;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement