Skip to content

Instantly share code, notes, and snippets.

@mgrider
Created April 30, 2019 16:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mgrider/64ead00ae2b642ad8fece4374d919749 to your computer and use it in GitHub Desktop.
Save mgrider/64ead00ae2b642ad8fece4374d919749 to your computer and use it in GitHub Desktop.
Quick and dirty rotate camera around something...
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);
}
}
}
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