public
Created

A compass ring that points itself to an object in 3D space

  • Download Gist
AlignedCompassRings.cs
C#
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
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);
}
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.