I need a script where I can look at an object and a piece of text appears above it when I look at it. Please help.
I’m thinking that if you want to just see the label when the object is in a specific eye-line range area. You could create a collider (box collider) with no mesh renderer attached and make it a child of your character or whatever is looking at this object. Check the isTrigger box and get it to trigger the label.
Make the label a child of the object and start with its mesh renderer disabled. Also, place it in a label layer.
Here is the trigger code. This is in C#:
void OnTriggerEnter( Collider other )
{
if( other.gameObject.layer == LayerMask.NameToLayer( "Labels" )
{
other.renderer.enabled = true;
}
}
void OnTriggerExit( Collider other )
{
if( other.gameObject.layer == LayerMask.NameToLayer( "Labels" )
{
other.renderer.enabled = false;
}
}
Hope that helps!!
EDIT: Also, a rigid body has to be attached to at least one of the entities entering the trigger.