• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
Question by zerox911 · May 29, 2012 at 10:45 AM · guiitemscollect

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..

Comment
You!

People who like this

1 Show 5
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image whydoidoit · May 29, 2012 at 10:49 AM 0
Share

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 presuming you don't just want one long string? A label with wordwrap would do that.

avatar image zerox911 · May 29, 2012 at 10:58 AM 0
Share

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

avatar image whydoidoit · May 29, 2012 at 11:03 AM 0
Share

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?

avatar image zerox911 · May 30, 2012 at 02:47 AM 0
Share

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??

avatar image flamy · May 31, 2012 at 12:50 PM 0
Share

GUI.Button(new Rect(),"",GUIStyle.none); i guess that you have to collect the items that popup in the screen.

1 Reply

· Add your reply
  • Sort: 
avatar image

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;

Comment

People who like this

0 Show 5 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image zerox911 · May 31, 2012 at 02:23 AM 0
Share

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

avatar image whydoidoit · May 31, 2012 at 02:33 AM 0
Share

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.

avatar image zerox911 · May 31, 2012 at 03:57 AM 0
Share

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..

avatar image whydoidoit · May 31, 2012 at 12:42 PM 0
Share

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

  • Make sure that all of the things that collider have a Collider attached - use a Box Collider or a Capsule Collider if you can - Mesh 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 isKinematic 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.

avatar image zerox911 · May 31, 2012 at 01:15 PM 0
Share

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

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

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

Pick Up like in Silent Hill 1 Answer

Collider Script Not Detecting 3 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges