Skip to content

Instantly share code, notes, and snippets.

@theta360developers
Created November 17, 2017 01:03
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 theta360developers/ae7e7d86fbe9a9739d39ebe81ea57deb to your computer and use it in GitHub Desktop.
Save theta360developers/ae7e7d86fbe9a9739d39ebe81ea57deb to your computer and use it in GitHub Desktop.
Follow gaze in Unity for THETA 360 images
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class followView : MonoBehaviour {
bool mouseDown = false;
float mouseX;
float mouseY;
Camera mainCamera;
void Start () {
mainCamera = GetComponent<Camera>();
}
void Update () {
if(Input.GetMouseButtonDown(0) && !mouseDown )
{
mouseDown = true;
mouseX = Input.mousePosition.x;
mouseY = Input.mousePosition.y;
}
else if(Input.GetMouseButtonUp(0) && mouseDown)
{
mouseDown = false;
}
}
void LateUpdate()
{
if(mouseDown)
{
float mouseXStop = Input.mousePosition.x;
float mouseYStop = Input.mousePosition.y;
float deltaX = mouseXStop - mouseX;
float deltaY = mouseYStop - mouseY;
float centerXNew = Screen.width / 2 + deltaX;
float centerYNew = Screen.height / 2 + deltaY;
Vector3 Gaze = mainCamera.ScreenToWorldPoint(new Vector3(centerXNew, centerYNew, mainCamera.nearClipPlane));
transform.LookAt(Gaze);
mouseX = mouseXStop;
mouseY = mouseYStop;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment