Skip to content

Instantly share code, notes, and snippets.

@knightcube
Created August 1, 2019 09:46
Show Gist options
  • Save knightcube/f907df367441515e2692dcf43f19aa55 to your computer and use it in GitHub Desktop.
Save knightcube/f907df367441515e2692dcf43f19aa55 to your computer and use it in GitHub Desktop.
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SimpleGazeCursor : MonoBehaviour
{
public Camera viewCamera;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
UpdateCursor();
}
private void UpdateCursor()
{
// Create a gaze ray pointing forward from the camera
Ray ray = new Ray(viewCamera.transform.position, viewCamera.transform.rotation * Vector3.forward);
RaycastHit hit;
if (Physics.Raycast(ray, out hit, Mathf.Infinity))
{
Debug.Log("Gazing at "+hit.transform.name);
}
else
{
Debug.Log("Gazing at nothing");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment