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 Aerilan · Apr 20, 2013 at 10:50 PM · javascripttimercrashing3dtext

My timer script makes Unity crash...

I am creating a game with a racing component, and wanted to create a on-screen timer to limit the time in a level. However for now I just want to make the timer count down every one second.

This is my code:

 var minute = 2;        //Minute place on Timer (3):43 //
 var second1 = 0;       //1st place on Timer 3:(4)3 //
 var second2 = 0;       //2nd place on Timer 3:4(3) //
 var IsActive = true;
 
 
 while(IsActive) // Toggle Timer //
 {
 
     while (second2 >= 0)                                            // Reducees second1 each second
     { 
     second2 = second2 - 1;
     yield WaitForSeconds(1);
     GetComponent(TextMesh).text = minute+":"+second1+second2;      // Refreshes timer every second
     }
     
     while (second2 == 0)                                            //Reduces second2 every 10 seconds
     {
     second1 == second1 - 1;
     second2 == 9;
     }
     
     while (second1 == 0)                                            //Reduces minute every minute. 
     {
     minute == minute - 1;
     second1 == 5;
     }
 
 }

It appears to me that this would work, however when I run it Unity crashes. Also try to ignore the fact that I am using 3dtext and not GUI text.

Thank You for your help :D

Comment
Add comment · Show 6
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 Aerilan · Apr 20, 2013 at 11:22 PM 0
Share

Thanks :) That helped a lot, now however I keep getting this error "BCE0044: expecting :, found '='. (12,17)"

However my line 12 (which looks like this second2 = second2 - 1; )

does not have a '=' at the specified location...

Thank You :D

avatar image Howey-Do-It · Apr 20, 2013 at 11:30 PM 0
Share

I am not absolutely certain about this, because I can't see the updated version of it. But in the original script you posted you were using "==" in several places that I think you meant to put "=".

You probably know this, but "==" is used when checking a value against another, and "=" is used to set a value to another.

Also, sometimes the character location doesn't seem to match up with actual error spot. If that's not creating the problem, put up the new code and I'll look at it.

God bless!

Howey

avatar image Aerilan · Apr 20, 2013 at 11:35 PM 0
Share

O$$anonymous$$ I tried that. I am still getting the same error.

Here is the updated script:

var $$anonymous$$ute ; //$$anonymous$$inute place on Timer (3):43 // var second1 ; //1st place on Timer 3:(4)3 // var second2 ; //2nd place on Timer 3:4(3) // var IsActive = true;

while(IsActive) // Toggle Timer // {

 if (second2 >= 0);                                            // Reducees second1 each second
 { 
 second2 = second2 - 1;
 yield WaitForSeconds(1);
 GetComponent(Text$$anonymous$$esh).text = $$anonymous$$ute+":"+second1+second2;      // Refreshes timer every second
 }
 
 if (second2 = 0)                                            //Reduces second2 every 10 seconds
 {
 second1 = second1 - 1;
 second2 = 9;
 }
 
 if (second1 = 0)                                            //Reduces $$anonymous$$ute every $$anonymous$$ute. 
 {
 $$anonymous$$ute = $$anonymous$$ute - 1;
 second1 = 5;
 }

Thank You :D

avatar image Howey-Do-It · Apr 20, 2013 at 11:52 PM 0
Share

Ok, I think I found the problem. I put it into monodevelop and kept getting an error in the script. The problem is here:

if (second2 >= 0);

Remove the semicolon and it should work fine. Also I am not sure if this affects anything negatively, but in "while(isActive) //Toggle Timer // {" the bracket is also commented out.

If this solves your problem, I will change my first comment to an answer so you set it as the answer and then other people can see it as well.

God bless!

Howey

avatar image Aerilan · Apr 21, 2013 at 12:18 AM 0
Share

TY for your help, I got it to work now.

Thanks for spending so much time on this.

God bless you too. :D

Show more comments

1 Reply

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

Answer by Howey-Do-It · Apr 20, 2013 at 10:54 PM

I am not a pro with Java so I could be wrong here. I believe "while" is what is causing the crash. I have used "while" before and it caused the same issue for me.

Again I could be totally off-base here but I think if you put it in the Update() function and used "if" instead of "while" it would work.

I hope that helps or at least puts you on the right track.

God bless!

Howey

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

12 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 avatar image avatar image

Related Questions

Can someone help me fix my Javascript for Flickering Light? 6 Answers

Setting Scroll View Width GUILayout 1 Answer

Is it possible to set a format for a playerprefs value? (Timer) 1 Answer

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

My timer freezes everytime I leave the scene and come back. 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