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 oliver-jones · Nov 17, 2010 at 03:43 PM · guitextureimageprogress-bar

Progress Bar Parallel To Game Progress - HELP

I would like to make a game progress bar that reads the values of 0% - 100%

I want the progress bar to fill with green (or any colour) on 100%, but is empty at 0% (eg: if game progress = 50%, then only half the progress bar will be green).

Can someone help me out here. I have no where to start.

I was thinking of using a green image that is 1px width by, say 20px height. And use a script that would 'stretch' the value of the width apparent to the percent of game complete (var GameComplete = 0;)

In JavaScript Please

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

1 Reply

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

Answer by denewbie · Nov 17, 2010 at 04:22 PM

In unity you have a choice of doing it in 2D or 3D

Of Course 2D is easier here.

1) Create 2 textures (Could be any image file format, jpg, png, psd etc) One can be green(the color of a filled bar) the other can be say white(the color of an empty bar)

2) use the bellow script:

(This is in C#)

float curScore = 0f; public float maxScore = 100f; // The maximium

public Texture2D whiteTexture; public Texture2D greenTexture;

void OnGUI (){ GUI.drawTexture( new Rect(0,0, 200, 20), whiteTexture ); GUI.drawTexture( new Rect(0,0, 200 * (currentScore/maxScore) , 20), greenTexture ); }

// Resets the score to 0 public void resetScore(){ currentScore = 0f; }

// Increments the score by one unit public void AddScore(){ if (currentScore < maxScore) currentScore++; }

Comment
Add comment · Show 3 · 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 denewbie · Nov 17, 2010 at 04:22 PM 0
Share

I just typed the code off the screen cause i didnt have unity with me so if there any problems oyu might find feeel free to msg me.

avatar image denewbie · Nov 17, 2010 at 04:24 PM 0
Share

Oh i forgot to mention. You'll also need to drag the textures into their respective places and then drag the script onto an object in the scene for it to work.

avatar image oliver-jones · Nov 17, 2010 at 04:24 PM 0
Share

Sorry - Forgot to say -- I'm a JavaScript person my self -- if you wouldn't $$anonymous$$d converting into JS for me?

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

No one has followed this question yet.

Related Questions

How can I prevent my GUI background texture from getting pixelated or stretched? 1 Answer

How can I add a distance cap to this script? 3 Answers

Timer progress bar 0 Answers

Health bar by percentage? (not drawing a box) 4 Answers

How do I trigger GUI elements 1 Answer


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