Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

How to show Game Objects using arrays C# scripting?

Discussion in 'Scripting' started by ninzpodador, Jan 14, 2015.

  1. ninzpodador

    ninzpodador

    Joined:
    Nov 26, 2014
    Posts:
    16
    Guys, I want to know what is the script to show my game object that I put in array....can help me please :(
    Screenshot 2015-01-15 04.04.37.png
     
  2. SevenHams

    SevenHams

    Joined:
    Dec 27, 2012
    Posts:
    67
    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.
     
  3. ninzpodador

    ninzpodador

    Joined:
    Nov 26, 2014
    Posts:
    16
    how to show the game object in array if I will do OntriggerEnter?
     
  4. SevenHams

    SevenHams

    Joined:
    Dec 27, 2012
    Posts:
    67
    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.
     
  5. jabez

    jabez

    Joined:
    Nov 2, 2013
    Posts:
    26
    Heyy there, Try something like
    Code (CSharp):
    1. for (int i = 0; i < ShowQ.Length; i++){
    2. Vector3 screenPos = Camera.main.WorldToScreenPoint(ShowQ[i].transform.position);
    3. Vector2 TextSize = GUIStyle.CalcSize(newGUIContent(ShowQ[i].name));
    4. GUI.Label(new Rect(screenPos.x, screenPos.y, TextSize .x, TextSize.y), ShowQ[i].name);
    5. }
    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?
     
    Last edited: Jan 14, 2015
  6. ninzpodador

    ninzpodador

    Joined:
    Nov 26, 2014
    Posts:
    16

    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.