Last active
September 9, 2016 08:56
-
-
Save radiatoryang/41352811ce0dfa1d945d to your computer and use it in GitHub Desktop.
simple script for my Recursive Reality class to make things with
This file contains 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 UnityEngine; | |
using System.Collections; | |
// DIRECTIONS FOR USE: | |
// put this script on ForwardDirection gameObject in your Oculus camera rig | |
// it will automatically call a function named "functionToCallOnLook" | |
// on every script component on that object (the object needs a collider too) | |
public class LookCast : MonoBehaviour { | |
// defined in inspector; this tells the raycast which collider layers will trigger it | |
public LayerMask raycastMask; | |
// defined in inspector; type the name of any function, without parentheses, e.g. "OnLook", NOT "OnLook()" | |
public string functionToCallOnLook = "OnLook"; | |
// Update is called once per frame | |
void Update () { | |
// setup variables required to fire a raycast... | |
// "ray" tells Unity where the raycast starts (origin), and which direction | |
Ray ray = new Ray( transform.position, transform.forward); | |
// "rayHit" is a temporary variable to help us remember which gameObject we looked at | |
RaycastHit rayHit = new RaycastHit(); | |
// this fires the raycast; a raycast will trigger only one collider at a time | |
if ( Physics.Raycast ( ray, out rayHit, 1000f, raycastMask ) ) { | |
rayHit.transform.SendMessage ( functionToCallOnLook, SendMessageOptions.DontRequireReceiver ); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment