i am able to identify an object with raycast and then print its name on GUI
but the problem is
the raycast identify one object at a time, when one object escape from the FOV of raycast and second comes then it print the name of second object
in the first image when my gaurd moves to yellow object it also display its name but when both comes together it tells only one
void Update()
{
playerInView = false;
foreach (RaycastHit hit in eyes.hits)
{
if (hit.transform && hit.transform.tag == "Player")
{
hittenGo = hit;
playerInView = true;
}
}
/*if (playerInView)
{
print ("Detected");
}*/
}
void OnGUI()
{
if (playerInView)
{
GUI.Box (new Rect (10, 10, 160, 60), "Title");
GUI.Label( new Rect(10, 10, 160, 60), hittenGo.collider.gameObject.name);
}
}
You’ll probably want to change your notice system to a list, you can Create a list of gameobjects and then affect each one individuall with a foreach heres an example.
//Make sure to include this line at the top of your script
using.System.Collections.Generic;
public List<Transform> tList;
// the Use of these individual objects
// starting with the Component Type, then the variable name we wish to use
// to reference them, Follow by the List they are in.
foreach(Transform target in tList) {
//this is where we do something to/for each object
Debug.Log(target.name + " Entered the radius of " + gameObject.name);
}
// examples of how to place/remove components to/from this list.
void OnTriggerEnter(Collider Other) {
tList.Add(Other.gameObject.transform);
}
void OnTriggerExit(Collider Other) {
tList.Remove(Other.gameObject.transform);
}
hope this helps if anythings unclear just let me know.
my problem solved but another issue appears
now both object in my scene detected and their name appears on GUI but only at the extreme left edge of raycast as in the picture
the changing in the code is now
RaycastHit hittenGo = new RaycastHit();
.
.
.
.
void OnGUI()
{
if (playerInView)
{
foreach (RaycastHit hittenGo in eyes.hits)
{
GUI.Label( new Rect(40, 25, 100, 40), hittenGo.collider.gameObject.name);
}
}