Display room list as Gui

0 votes
hey i need to display the room list that i get from the ongetallroomsdone callback.i can display the array as a log but not as gui because the listener.cs script does not exist in the scene. can u please tell me how to display the ids from the script or from any other script. currently i am trying to call the gui function inside the listener script.thanks!
asked Feb 11, 2015 in AppWarp by Mihir Solanki (27 points)

1 Answer

0 votes
Hi,

You can display room IDs retrived through getAllRoomsDone as you would display any list of data on GUI. GUI is part of your game and it depends on you how you want to display it. You can google on how to display a list of items in Unity.

With Unity 4.6 it can be very easy. It already has support for lots of UI components. You should check out Unity's documentation site.

Thanks
answered Feb 11, 2015 by Suyash Mohan (900 points)
i know how to display it suyash.my problem is that gui command can only be called from an ongui function.when i am calling the function in the listener.cs script
it does not run since the script is not in the scene. so i need a method to transfer the variable array to another scriptIn the scene and then display the list.please help
Hi! Mihir,

You can create a new script inheriting from MonoBehaviour. Use GetComponent method to get the script from the target game object. Now you call any public method of your script. Example :

YourScript script = GameObject.Find("targetGameObject").GetComponent<YourScript >();
script.yourMethod (yourList);

You can also try using sendMessage() method of GameObject. Or you can even use a naive approach like creating global static objects to hold information.

We are BaaS providers. We are not game developers. So we can't give you good answer on how transfer a variable from one script to another in Unity. That's why I asked you to google it.

Thanks
how can i use send message and get component if the script is not attached to any object in the scene.the script is only in the project file and not in the actual scene
It will not work then. It has to be assigned to a gameObject
i attached te listener script to an object and i am now sending a message to it like this:-
for (int i=0; i<4; i++)
                    {
                        Debug.Log ("rooms");
                        Log ("Room ID : " + eventObj.getRoomIds () [i]);
                        array[i]=eventObj.getRoomIds () [i];


                        Debug.Log ("Room ID : " + eventObj.getRoomIds () [i]);
                        k.SendMessage("Sent",array[i]);
                        Debug.Log("sent");

                            }

the sent function in the receiving object is like this-
var array=new Array();
var ra=new Array();
function Sent(ra)
{
   Debug.Log("receieved");
   array=ra;
   }


function OnGUI()
        {
            for (var j=0; j<array.length; j++)
            {
               
                GUI.Label (new Rect (700, 20 * j, 50, 20), "room:" + array [j]);
                                }
                       
                }
               
but the loop only executes once and that too only till the array assign.i cannot send a message to the k gameobject.help
Hi! I will again request you to ask such questions on Unity forum or similar forums. We are not game developers we can't give you good answers for such situations
Download Widgets
Welcome to ShepHertz Product line forum, where you can ask questions and receive answers from the community. You can also reach out to us on support@shephertz.com
...