martes, 16 de agosto de 2011

Mostrar Nombre de Objetos Cercanos

var texto : TextMesh; //creamos un 3dText y lo ponemos como hijo del player

function Update () {

if (Input.GetKey("e")) //si mantenemos pulsado "e"...
{
var hit : RaycastHit;
if (Physics.Raycast (transform.position, transform.forward, hit, 4)) { //lanzo un rayo hacia adelante
if (hit.collider.tag == "Leible") // si choca el rayo con algo marcado como leible (creamos el tag Leible)
{
texto.text = hit.collider.name; // aplicamos el nombre del objeto al texto 3d
texto.gameObject.active = true; // y activamos el texto 3d
}

}
else
texto.gameObject.active = false; // si dejamos de chocar mirar al objeto o nos alejamos...
o
}
else
texto.gameObject.active = false; // si dejamos de pulsar la tecla ... no se muestra el texto
}


function Start() { // al empezar el juego el texto 3d se oculta
texto.gameObject.active = false;
}

No hay comentarios:

Publicar un comentario

Deja tus comentarios o dudas.