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 Lucifer95 · Dec 16, 2014 at 09:44 AM · progress bar

making a progress bar in javascript

 the bar is not filling up and also one number is displayed in textblock and level loads..
 code:
 
 #pragma strict
 var levelname:String;
 var loadingscreen:GameObject;
 var emptybar:GameObject;
 var bar:GameObject;
 var percentage:GameObject;
 var oldscreen:GameObject;
 private var loadprogress:int=0;
 
 function Start () {
 loadingscreen.active=false;
 emptybar.active=false;
 bar.active=false;
 percentage.active=false;
 }
 
 function Update () {
 if(Input.GetKey(KeyCode.Space))
 press();
  if(Input.touchCount > 0)
  {
 
 var touch: Touch = Input.touches[0]; 
     if(touch.phase == TouchPhase.Began && guiTexture.HitTest(touch.position)){
         press();
     
     }
     
 }
 }
 
 function press()
 {
     this.guiTexture.pixelInset.width=-8;
     this.guiTexture.pixelInset.height=-8;
     yield WaitForSeconds(.2);
     this.guiTexture.pixelInset.width=0;
     this.guiTexture.pixelInset.height=0;
     yield StartCoroutine("load");    
 }
 function load()
 {
 oldscreen.active=false;
 loadingscreen.active=true;
 emptybar.active=true;
 bar.active=true;
 percentage.active=true;
 var async:AsyncOperation=Application.LoadLevelAsync("level 1");
 while(async.progress<=1)
 {
 Debug.Log(async.progress*100);
 loadprogress=async.progress*10;
 bar.transform.localScale=Vector3((loadprogress/3),bar.transform.localScale.y,bar.transform.localScale.z);
 percentage.guiText.text="Loading "+loadprogress+" %";
 yield null;
 }
 }`enter code here`

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by VanZeebroeck · Dec 16, 2014 at 10:03 AM

You are using yield in your press method. That makes it a co routine, and co-routines always have to be called with StartCoroutine, or they will do nothing. Try this:

   StartCoroutine(press());

http://docs.unity3d.com/ScriptReference/MonoBehaviour.StartCoroutine.html

Also if I look at your mobile version of your input it seems you will want to use Input.GetKeyDown(KeyCode.Space), this way your press method will only be executed once every time you push the space bar, unless it is meant to be continuous update as long as the user holds the space bar down.

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

Answer by Lucifer95 · Dec 16, 2014 at 12:18 PM

k thanx...solved it

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

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

The best way to damage an enemy (js) 2 Answers

Error with Camera WorldtoScreenPoint 1 Answer

How to make a scene load more random than others? 1 Answer

Trying to pick one or the other 1 Answer

Disable/Enable Colliders 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