How to show Game Objects using arrays C# scripting?

Guys, I want to know what is the script to show my game object that I put in array…can help me please :frowning:

Your array doesn’t exist. You need public GameObject[ ] showQ = new GameObject#. The # is how big you want the array to be.

You’re also trying to add things that are not GameObjects to a GameObject array.

how to show the game object in array if I will do OntriggerEnter?

What do you mean by show? You can access a GameObject in an array just like any other type in an array. However, the other issue is that you are also not actually putting any game objects in the array. You’d need to create game objects, either in the editor or in the code, and put them in the array in the first place to be able to do anything at all with them.

Heyy there, Try something like

for (int i = 0; i < ShowQ.Length; i++){
Vector3 screenPos = Camera.main.WorldToScreenPoint(ShowQ[i].transform.position);
Vector2 TextSize = GUIStyle.CalcSize(newGUIContent(ShowQ[i].name));
GUI.Label(new Rect(screenPos.x, screenPos.y, TextSize .x, TextSize.y), ShowQ[i].name);
}

This may need a few adjustments as i didn’t do it in mono develop. I don’t know what you mean by show? Do you mean find the gameobject within the list that the trigger has collided with? or what?

Yes sir, what I mean is that If my Player will collide to a box, then, the game object questions that I put in a array will pop up or show.

See below the video I made hoping that you can help me…using C# script.

https://www.youtube.com/watch?v=Hn2waofulP0