Skip to content

Instantly share code, notes, and snippets.

@thenormalsquid
Created October 16, 2016 18:03
Show Gist options
  • Save thenormalsquid/c83d4e65637ab4ec2768ea148889d0da to your computer and use it in GitHub Desktop.
Save thenormalsquid/c83d4e65637ab4ec2768ea148889d0da to your computer and use it in GitHub Desktop.
eyes.cs
public class UpdateEyeAnchors : MonoBehaviour
{
GameObject[] eyes = new GameObject[2];
string[] eyeAnchorNames = { "LeftEyeAnchor", "RightEyeAnchor" };
void Update()
{
for (int i = 0; i < 2; ++i)
{
// If the eye anchor is no longer a child of us, don't use it
if (eyes[i] != null && eyes[i].transform.parent != transform)
{
eyes[i] = null;
}
// If we don't have an eye anchor, try to find one or create one
if (eyes[i] == null)
{
Transform t = transform.Find(eyeAnchorNames[i]);
if (t)
eyes[i] = t.gameObject;
if (eyes[i] == null)
{
eyes[i] = new GameObject(eyeAnchorNames[i]);
eyes[i].transform.parent = gameObject.transform;
}
}
// Update the eye transform
eyes[i].transform.localPosition = InputTracking.GetLocalPosition((VRNode)i);
eyes[i].transform.localRotation = InputTracking.GetLocalRotation((VRNode)i);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment