Last active
August 29, 2015 14:03
-
-
Save josephjaniga/e1a015b8448c08caf229 to your computer and use it in GitHub Desktop.
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; | |
[RequireComponent (typeof (GUIText))] | |
public class ObjectLabel : MonoBehaviour { | |
public string npcName; | |
public Transform target; // the object the label should follow | |
public Vector3 offset = Vector3.up; // Units in world space to offset; 1 unit above object by default | |
public bool useMainCamera = true; // Use the camera tagged MainCamera | |
public Camera cameraToUse; // Only use this if useMainCamera is false | |
Camera cam; | |
Transform thisTransform; | |
// Use this for initialization | |
void Start () { | |
guiText.text = npcName; | |
thisTransform = transform; | |
if (useMainCamera) | |
cam = Camera.main; | |
else | |
cam = cameraToUse; | |
} | |
// Update is called once per frame | |
void Update () { | |
thisTransform.position = cam.WorldToViewportPoint(target.position + offset); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment