Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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
0
Question by xKroniK13x · Nov 22, 2012 at 04:16 AM · guitexturelayout

Layering GUI Texture

Hey guys, I am trying to do something that I thought should be easy.

I am having levels download and have a rating (all server side, all done). The rating is between 0 and 5, and contains up to one decimal. So like... 2.7 would be a rating.

I am trying to display a set of 5 stars. I made these in photoshop. I made 2 images, one of empty stars, and one of full stars, each obviously have 5 stars.

I want the empty stars to all appear, and then the full stars fill in. Now, this is similar (I thought) to the concept found here: http://answers.unity3d.com/questions/11892/how-would-you-make-an-energy-bar-loading-progress.html

However, I just can't seem to get it work. I need it to appear in a GUI Layout, as there are going to be 10 levels per page. I have that loop all done, and it displays the rating number in a GUILayout.Horizontal() area. I am writing this in UnityScript/Java.

I have tried making a GUI box and then having these stars appear on top of it, which works if the stars are FULL, but only if they are full. I essentially need them to crop, instead of resize. I'm truly lost here. Any help would be so greatly appreciated.

Comment
Add comment
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

3 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Griffo · Dec 02, 2012 at 11:27 AM

I don't think you can put GUI.BeginGroup in a GUILayout.BeginHorizontal(); or GUILayout.BeginVertical();

So the way I would do it is ..

 #pragma strict
 
 var starsEmpty : Texture2D;
 var starsFull : Texture2D;
 
 public var starRating : int[] = [0,4,3,1,2,4];
 public var starNames : String[] = ["Mike","Steve","Paul","Harry","Stuart","Kevin"];
 
 function Start () {
 
 }
 
 function Update () {
 
 
 }
 
 
 function OnGUI(){
 
     var adjust : int;
 
 for(var j = 0; j < 6; j++){
 
 // Here you would call the players rating .. by this script: parsed[i]["rating"]
     adjust = starRating[j];
     adjust = adjust + 25 * adjust;
 
     GUI.BeginGroup(Rect(0,j*33,100,24));
     GUI.DrawTexture(Rect(0,0,100,24), starsEmpty);
     GUI.EndGroup();
 
     GUI.BeginGroup(Rect(0,j*33,adjust,24));
     GUI.DrawTexture(Rect(0,0,100,24), starsFull);
     GUI.EndGroup();
 }
 
     GUILayout.BeginArea (Rect (100,0,200,200));
 for(var i = 0; i < 6; i++){
 
     GUILayout.BeginHorizontal("box");
     GUILayout.Label("Star rating in Level " + i);
 // Here you would call the name .. "Level name: " + parsed[i]["name"]
     GUILayout.Label(starNames[i]);
     
     GUILayout.EndHorizontal();
     }
     GUILayout.EndArea ();
 }

Use the below Textures with this scrip to try it, then alter to suite your requirements .. Hope this helps you out.

Stars02


stars02.zip (27.5 kB)
Comment
Add comment · Show 9 · 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 xKroniK13x · Dec 03, 2012 at 03:51 AM 0
Share

This was very close. Sadly, it was off by just a bit. After a little bit of tweaking, I got all of the stars to appear how I needed; however, without me thinking about it... some of the information stretches out certain columns, so the stars no longer lined up... that's hard to explain in words, so I'll include a screenshot link below.

The only solution I could think of, which I can do if I need to, is to have the description in a scrollbox of a set height so that it doesn't stretch the rows. I'd prefer them as is, but I can add a scrollbox if that's what I need to do!

Screenshot: http://www.coreymccown.com/images/GUIClose.png

Thanks for the help man. I really appreciate it.

avatar image Griffo · Dec 03, 2012 at 10:17 AM 0
Share

Ok, glad it helped, can you mark it as answered please, now I've seen a screen shot of what you're trying to achieve I'll have a think about it, if I come up with something I'll let you know.

Do you $$anonymous$$d posting the code that done the screenshot ?

avatar image xKroniK13x · Dec 03, 2012 at 02:03 PM 0
Share

I'll P$$anonymous$$ you a link to the download level file on the Unity Forums that way you can see the entire script.

avatar image Griffo · Dec 03, 2012 at 02:51 PM 0
Share

Is this development for PC ?

avatar image xKroniK13x · Dec 03, 2012 at 03:37 PM 0
Share

Yes. It'll be a web player game with an optional client download to play it offline. No android or iOS at the time. I sent a link to an archive that has the stars I am using as well as the level list script in a private message on the forums. :)

Show more comments
avatar image
0

Answer by Griffo · Dec 01, 2012 at 01:18 PM

Try this, create a empty game object, drop this script onto it then add the textures I've supplied below Stars.zip, press "z" to test it and alter to suite your requirements.

And don't forget to set the texture type of the star to GUI in the Inspector.

 #pragma strict
 
 var starsEmpty : Texture2D;
 var starsFull : Texture2D;
 
 private var adjustStars : float;
 
 function Start () {
 
 }
 
 function Update () {
 
 if (Input.GetKeyDown ("z")){
     adjustStars = adjustStars + 50;
     }
 }
 
 // Adjust the health bars of the enemy
 function OnGUI(){
 
 var adjust : float = adjustStars;
 
 // Place the GUI at the top of the screen
     GUI.BeginGroup(Rect(Screen.width / 2 - 150,Screen.height - Screen.height + 50,200,48));
     GUI.DrawTexture(Rect(0,0,200,48), starsEmpty);
     GUI.EndGroup();
 
 // Place the GUI at the top of the screen
     GUI.BeginGroup(Rect(Screen.width / 2 - 150,Screen.height - Screen.height + 50,adjust,48));
     GUI.DrawTexture(Rect(0,0,200,48), starsFull);
     GUI.EndGroup();
 }

Stars.zip


stars.zip (49.0 kB)
Comment
Add comment · 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 xKroniK13x · Dec 01, 2012 at 03:56 PM 0
Share

That works, however, how could I get that into the loop that displays all of the levels? It's inside of a GUILayout.BeginHorizontal(); and if I just use GUI it stacks all of them in one spot =/ Thanks a lot for the help so far!

avatar image Griffo · Dec 01, 2012 at 04:11 PM 0
Share

Not sure what you'r asking but I think all you need to do is use a global variable for the line

 var adjust : float = adjustStars;

something like

 var adjust : float = globalVars.GetComponent(GlobalVars).starRating;

and check it in the loop with some thing like

 private var globalVars : GameObject;
 
 function Awake(){
 
     globalVars = GameObject.Find("Global Vars");
 }
 
 function Update(){
 
     globalVars.GetComponent(GlobalVars).starRating;
 }
 
avatar image Griffo · Dec 01, 2012 at 04:14 PM 0
Share

Or show the part of the code you want it inserted into ..

avatar image xKroniK13x · Dec 02, 2012 at 06:11 AM 0
Share

The code I'm inserting this into is like this: (This is a shortened version):

 
for(var i = 0; i < parsed.length; i++){
 	GUILayout.BeginHorizontal();
	 	GUILayout.BeginVertical();
			GUILayout.Label("Level name: " + parsed[i]["name"],GUILayout.Width(w1));
			GUILayout.BeginHorizontal(rating,GUILayout.Width(150),GUILayout.Height(29));
				//Rating stars go here! Variable obtained by this script: parsed[i]["rating"] . This is unique for every level in the loop.
			GUILayout.EndHorizontal();
		GUILayout.EndVertical();
	GUILayout.EndHorizontal();
}
 

It needs to go where that comment is, each time the loop goes through. This is all part of a GUILayout.BeginArea, so they all end up stacking on top of each other into a nice list of all the levels. The rating is being obtained through a JSON parser, as is all of the other information. For each iteration i, the rating, name, etc will change.

Thanks man!

avatar image Griffo · Dec 02, 2012 at 11:28 AM 0
Share

I've put a new answer up above.

avatar image
0

Answer by Griffo · Dec 03, 2012 at 09:12 PM

Hi, Here is a quick workaround I've done, (a very short script) it rounds the players score to .5 and uses a set of star textures to match, drop the star textures in the array in the inspector, the star ratings will stay within the GUILayout if you add more text to one, it might help get your project where you want it.

Stars


stars.zip (228.3 kB)
Comment
Add comment · Show 1 · 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 xKroniK13x · Dec 04, 2012 at 02:33 AM 0
Share

It does work very well. I decided to go with having set heights for the description, and it looks better than I anticipated. The scroll bars only come up if it's a large description, and it doesn't really look out of place. Thanks a ton for all of your help. I am very grateful for it, and it seems like you have took a lot of time out of your day to help out, and that's rare to find these days. 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.

Follow this Question

Answers Answers and Comments

10 People are following this question.

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

Related Questions

Layouts with GUITextures 2 Answers

Scaling a guitexture hierarchy and maintaining layout in code 0 Answers

Reduce Draw call for Multiple GUI Textures with same Texture 1 Answer

pickup count on GUI 1 Answer

3d Mask on GUI Texture, its possible? 0 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