Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by marlonh1994 · Nov 09, 2015 at 04:20 AM · javascriptunity 2dunity5stringspace shooter

How would I load a new scene when a score that is scored in a string is reached?

This is a code that I am working on for a space shooter. Part of it works and my score does increase by 7 every second but my script does not load my scene when the number reaches 1000. I have made sure that my scene is a part of my build settings and I have tried some fixes but it doesn't load even though I don't get any sort of error. Any Ideas?

 #pragma strict

 function Start(){
 InvokeRepeating("EachSecond",1.0,1.0);
 }
 
 var score: int = 0;
 var addscore = 7;
 
 function EachSecond()
 {
    score=score+addscore;
 }
 
 function OnGUI(){
 GUI.Box(Rect(1000,10,100,25), score.ToString());
 }

 function WinningScore()
   {
         if (score >= 1000 )
         {
              Application.LoadLevel("Win");
         }
      }
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
-1

Answer by lienadnellum · Nov 09, 2015 at 06:01 PM

I am pretty sure that variable should be an integer that corresponds to the scene you want to load in build settings for loading levels make a new scene, add your stuff in it, then save scene call it "level1", make a new scene put your stuff into it and save the scene call it "level2". in build settings add , "level1", then add "level2", in build setting you should have two scenes, one called "level1" which will have 0 by it and "level2" which will have a 1 by it. this is the code I would use for something like that, i am showing you this because I know it works, it will count up to 100 then load "level2" which has a level prefix of "1" " var Score : int = 0; var ScoreToAdd : int = 7; var ScoreAddInterval : float = 1;

function Start () {

StartScoreLooping();

} function OnGUI(){ GUI.Box(Rect(100,10,100,25), Score.ToString()); } function StartScoreLooping () { var i = 1; for(i=1;i>0;i++){ yield WaitForSeconds(ScoreAddInterval); Score += ScoreToAdd; if(Score >= 100){ Application.LoadLevel(1); }

         }

}" I am pretty sure the Application.LoadLevel("win"); needs to be changed to the integer that is next to the scene "win" in build settings. I hoped this helped you out.

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 Statement · Nov 09, 2015 at 07:53 PM 0
Share

I am pretty sure that variable should be an integer [...] I am pretty sure the Application.LoadLevel("win"); needs to be changed to the integer

No. Application.LoadLevel: "Loads the level by its name or index."

avatar image
0

Answer by Statement · Nov 09, 2015 at 07:48 PM

You're never calling WinningScore.

 function EachSecond()
 {
     score=score+addscore;
     WinningScore(); // You forgot to call WinningScore!
 }
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

6 People are following this question.

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

Related Questions

Unity 2D Following player on the x-axis only 1 Answer

How do I turn off the previous object? 1 Answer

how to fix menu button "play" 1 Answer

Can someone please help me fix the script? in unity3D to move forwards and backwards by swiping to the screen,Rotate and move forward script not working 0 Answers

Format Exception when trying to parseFloat(String) 2 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