so i’m using raycast hit to detect gameobject and then execute animations and load scenes, but the problem is when i want to add GUI text interaction with raycast hit, the physics.raycast detects all of the gameobjects so the gui text appears everywhere. how to make the raycast hit to be more specific in checking gameobject/ignore the others?
here’s the script :
var distance : float =2;
var theGuiObject : GUIText;
var liftSound : AudioClip;
var Metal : GameObject;
function Update()
{
var dir = transform.TransformDirection(Vector3.forward);
var hit : RaycastHit;
Debug.DrawRay(transform.position, dir * distance, Color.blue);
if (Physics.Raycast(transform.position, dir, hit, distance))
{ theGuiObject.enabled = true;
if(Input.GetKey(KeyCode.E) && (hit.collider.gameObject.tag == "trigger")){
audio.PlayOneShot(liftSound, 1.0 / audio.volume);
Metal.animation.Play("LiftUp");
}
} else { theGuiObject.enabled = false; }
if (Physics.Raycast(transform.position, dir, hit, distance))
{
if(Input.GetKey(KeyCode.E) && (hit.collider.gameObject.tag == "turun")){
audio.PlayOneShot(liftSound, 1.0 / audio.volume);
Metal.animation.Play("LiftDown");
}
}
}
any suggestions?