- Home /
how can i collect items that fills up a GUI??
ok.. i already have a script for doing an array of words to put in to the GUI.
now .. i want the GUI to fill up as i collect words, letters, objects , etc..
so when i collected up to a certain amount of items...
the GUI will fill up as i collect..
[word collected] -> [++++GUI++++]
and what's the best type of GUI for this..??
some help, tips and solutions are appreciated..
thank you for your patience and attention..
Haven't got time right now for a solution - someone else may help with that. Sounds to me like you need to be considering GUILayout as it is pretty good at stretching things to fill the available space. But you are going to have to write some code to manage either vertical or horizontal blocks of the words etc that you collect.
That's presu$$anonymous$$g you don't just want one long string? A label with wordwrap would do that.
ok take your time...
i don't quite understand your explanation..
you are saying that i should use GUI.Layout for this problem..
and adjusting the vertical and horizontal with a variable..
the "long string" and "label with wordwrap" bugs me a little though..
no offence.. :P
If you use BeginArea at the start of a GUILayout OnGUI then you can use BeginVertical/EndVertical BeginHorizontal/EndHorizontal
So BeginHorizontal / EndHorizontal - if you put things in between the two there then they fit horizontally across the screen, stretching to fill the area that you defined. The more things you add, the narrower each one get.
You would use labels styled as boxes I would imagine.
Vertical works the same way - (but vertically of course!) so you would need a mix of the two, starting new rows when another became full.
But if you just want words - then is not just using a long string an option? I guess you might want different formatting etc?
so it would be like...
function OnGUI(){
GUILayout.BeginHorizontal();
something2 about GUI labels -
GUILayout.EndHorizontal();
}
i got that part covered..
now its the string..
how do i create to put it to the GUI??
GUI.Button(new Rect(),"",GUIStyle.none); i guess that you have to collect the items that popup in the screen.
Answer by whydoidoit · May 30, 2012 at 10:55 AM
Ok I'm going to attempt an answer without fully understanding the problem :)
function OnGUI() {
GUILayout.BeginArea(Rect(20,20,600,600)); //Use your own dimensions :)
GUILayout.BeginVertical();
for(var i = 0; i < totalItems; i+=10) //10 is max items per row
{
GUILayout.BeginHorizontal();
for(var j=0; j<10 && i+j < totalItems; j++)
{
GUILayout.Label(item[i+j]);
}
GUILayout.EndHorizontal();
}
GUILayout.EndVertical();
GUILayout.EndArea();
}
Where items is an array or list of strings and totalItems is the number in it. You might be using an Array or ArrayList for items so in that case you can just replace totalItems with items.Length;
a rough assumption..
so...
i'll be starting off with =
var items : ArrayList;
var totalTiems : int;
something like that right..
anything i can do for any other functions, like Update, Start etc3??
thanks
Sure I can help with that - but I need to know what you'd like to do - do you want advice on writing Collision detection in a 3d world etc?
Your assumptions are fine - we can skip totalItems if we are using an ArrayList and just relace that in my example with items.Length.
owh.. ok... well i need help on the Collision/Trigger events to trigger the GUI..
as i collect items.. like a ball.. i'll keep on collecting it till i fill up the gauge in the screen.. so i can move on to the next level..
as i move to the next level.. the gauge remains the same.. but the items change per level.. and so as the difficulty of that level..
one question.. is it possible that the gauge can be shaped..?? like the gauge in forms of one simple word.. like BALL.. as i collect the items .. the word will slowly fill up according to the amount of items are collected..
i apologize if im disturbing you with my questions..
Hey no problem:
Right so I probably can't write it all for you, but I can certainly point you in the right direction.
To do the collision stuff
$$anonymous$$ake sure that all of the things that collider have a Collider attached - use a Box Collider or a Capsule Collider if you can - $$anonymous$$esh collider if you need high accuracy
You need to put a rigidbody on at least one of the components involved in triggering - probably the player. If you don't want to use physics to move it, make its is$$anonymous$$inematic property true.
Write an OnTriggerEnter function on the player - it gets called with the thing the player hit. Use the .gameObject on that to get the item hit and add it to the list of things collected, then call Object.Destroy() on that gameObject (the one you got from the parameter to the trigger function).
So I think I see what you want now with the gauge - well you could fill something up, there would be a number of ways to do it - none of them very easy - I think my earlier answer will cover too much of the screen for you perhaps. So the best way I can think of is still a little tricky:
Using a paint package draw the word you want to fill in a texture - you can make it fancy this way
In your OnGUI use DrawTexture to draw it onto the screen - but draw only the % of the height that equals the current percentage complete
If you want to make that fancy - you could create two textures - one showing an outline and the other showing it filled. You would draw the filled one per my instructions above and then draw the outline (which needs to have a transparent background) over the top of it.
wow...
its way complicated than i thought..
lol..
i can understand the collision part...
the gauge thingy is a little unclear..
need some more lights on that area please...
thanks...
Your answer
Follow this Question
Related Questions
How to make a selection list using either GUI system? 0 Answers
Equipting a Item/Weapon 1 Answer
GUI.Window write elements by pages 0 Answers
Collider Script Not Detecting 3 Answers
Pick Up like in Silent Hill 1 Answer