Created
April 5, 2012 15:37
-
-
Save LoganBarnett/2312011 to your computer and use it in GitHub Desktop.
A compass ring that points itself to an object in 3D space
This file contains hidden or 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; | |
| public class AlignedCompassRings : MonoBehaviour { | |
| public GameObject yRing; | |
| public GameObject north; | |
| public float zOffset = 0.0f; | |
| void Awake() { | |
| yRing.SetActiveRecursively(false); | |
| } | |
| void Start() { | |
| yRing.SetActiveRecursively(true); | |
| } | |
| void Update() { | |
| yRing.transform.LookAt(north.transform.position); | |
| var localRotation = yRing.transform.localRotation.eulerAngles; | |
| yRing.transform.localRotation = Quaternion.Euler(localRotation.x, localRotation.y, zOffset); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment