Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class CheckScreenEdges : MonoBehaviour
- {
- public enum ScreenEdge
- {
- None,
- Up,
- Down,
- Right,
- Left,
- UpRight,
- UpLeft,
- DownRight,
- DownLeft
- }
- [SerializeField] private CameraFreeFly cameraFreeFly;
- private ScreenEdge edge;
- private void LateUpdate()
- {
- CheckCursorPosition();
- Vector3 direction = Vector3.zero;
- switch (edge)
- {
- case ScreenEdge.None:
- break;
- case ScreenEdge.Up:
- direction = Vector3.forward;
- break;
- case ScreenEdge.Down:
- direction = Vector3.back;
- break;
- case ScreenEdge.Right:
- direction = Vector3.right;
- break;
- case ScreenEdge.Left:
- direction = Vector3.left;
- break;
- case ScreenEdge.UpRight:
- direction = Vector3.forward + Vector3.right;
- break;
- case ScreenEdge.UpLeft:
- direction = Vector3.forward + Vector3.left;
- break;
- case ScreenEdge.DownRight:
- direction = Vector3.back + Vector3.right;
- break;
- case ScreenEdge.DownLeft:
- direction = Vector3.back + Vector3.left;
- break;
- default:
- break;
- }
- cameraFreeFly.moveDirection = direction;
- }
- private void CheckCursorPosition()
- {
- float offset = 30;
- edge = ScreenEdge.None;
- if (Input.mousePosition.x < offset)//У левого края
- {
- edge = ScreenEdge.Left;
- if (Input.mousePosition.y < offset)//У верхнего края
- {
- edge = ScreenEdge.DownLeft;
- return;
- }
- if (Input.mousePosition.y > Screen.height - offset)//У нижнего края
- {
- edge = ScreenEdge.UpLeft;
- return;
- }
- return;
- }
- if (Input.mousePosition.x > Screen.width - offset)//У правого края
- {
- edge = ScreenEdge.Right;
- if (Input.mousePosition.y < offset)//У нижнего края
- {
- edge = ScreenEdge.DownRight;
- return;
- }
- if (Input.mousePosition.y > Screen.height - offset)//У верхнего края
- {
- edge = ScreenEdge.UpRight;
- return;
- }
- return;
- }
- if (Input.mousePosition.y > Screen.height - offset)//У верхнего края
- {
- edge = ScreenEdge.Up;
- return;
- }
- if (Input.mousePosition.y < offset)//У нижнего края
- {
- edge = ScreenEdge.Down;
- return;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement