cdiego

WorldToScreenPoint - Unity

Jul 19th, 2014
327
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.12 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3. /// <summary>
  4. /// Este script se adjunta al GameObject que quiere mostrar su etiqueta
  5. /// En este caso al Cube
  6. /// En este ejemplo se muestra el funcionamiento de WorldToScreenPoint y como mostrar etiquetas
  7. /// Tambien con NGUI, descomentar las 2 lineas debajo de //NGUI
  8. /// </summary>
  9. public class mundo : MonoBehaviour {
  10.  
  11.     public GameObject ngui_barra;
  12.     public Camera camara2;
  13.     void Start () {
  14.         ngui_barra = GameObject.Find ("barra");
  15.  
  16.  
  17.     }
  18.    
  19.     // Update is called once per frame
  20.     void Update () {
  21.  
  22.  
  23.     }
  24.     void OnGUI()
  25.     {
  26.         //NGUI
  27. //      Vector3 pos_pantala = Camera.main.WorldToScreenPoint (transform.position);
  28. //      ngui_barra.transform.position = camara2.ScreenToWorldPoint( pos_pantala);
  29.         //UNITY
  30.         Vector3 pos_pantala = Camera.main.WorldToScreenPoint (transform.position);
  31.         float escala = pos_pantala.z / 10;
  32.         GUIStyle st = new GUIStyle ();
  33.         st.fontSize = Mathf.CeilToInt( 20/escala);
  34.         st.alignment = TextAnchor.MiddleCenter;
  35.         GUI.Label(new Rect(pos_pantala.x - 70/2/escala, Screen.height - pos_pantala.y -40/escala, 70/escala, 20/escala), "Etiqueta",st);
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment