Created
April 30, 2019 16:46
-
-
Save mgrider/64ead00ae2b642ad8fece4374d919749 to your computer and use it in GitHub Desktop.
Quick and dirty rotate camera around something...
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
namespace AbstractPuzzle | |
{ | |
public class CameraManager : MonoBehaviour | |
{ | |
public GameObject cameraObject; | |
public GameObject centerObject; | |
/// <summary> | |
/// Rotate method | |
/// </summary> | |
public void RotateByOffset(float offset) | |
{ | |
cameraObject.transform.RotateAround(centerObject.transform.position, Vector3.up, offset * -0.2f); | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
using UnityEngine.UI; | |
using UnityEngine.EventSystems; | |
namespace AbstractPuzzle | |
{ | |
public class UIInputBehavior : MonoBehaviour, IPointerDownHandler, IBeginDragHandler, IDragHandler, IEndDragHandler | |
{ | |
private Vector2 lastDragPosition; | |
private CameraManager cameraManager; | |
/// <summary> | |
/// Start | |
/// </summary> | |
void Start() | |
{ | |
cameraManager = FindObjectOfType<CameraManager>(); | |
} | |
/// <summary> | |
/// IBeginDragHandler, IDragHandler, IEndDragHandler - Drag support | |
/// </summary> | |
public void OnBeginDrag(PointerEventData data) | |
{ | |
//Debug.Log("OnBeginDrag()"); | |
lastDragPosition = data.position; | |
} | |
public void OnDrag(PointerEventData data) | |
{ | |
if (lastDragPosition != null) | |
{ | |
float offsetX = lastDragPosition.x - data.position.x; | |
cameraManager.RotateByOffset(offsetX); | |
} | |
lastDragPosition = data.position; | |
} | |
public void OnEndDrag(PointerEventData data) | |
{ | |
//Debug.Log("OnEndDrag()"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment