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
1
Question by Velketor · Mar 08, 2011 at 04:02 PM · levelloadlevelobjective

Score / Loading Level

I have a level that requires 10 points to win. Right now, I can get 10 points, but the next level does not load. Can anyone tell me how to script a level to load upon completion of the score reaching 10? All help is greatly appreciated. Thank you!

Shawn


Updated with Shawns code in comment reply:

I am lost, here is my code:

var score = 0;

function Update() { if (score > 4) { Application.LoadLevel(1); } }

And this is my score script:

var cam : GameObject; var Win : GameObject; var Lose : GameObject; var score = 1;

function AddToScore() { ++score; guiText.text = "Score: " + score.ToString(); }

function SubtractFromScore() { --score; guiText.text = "Score: " + score.ToString(); }

~Statement


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 Statement · Mar 08, 2011 at 04:49 PM

You can do something like this if your levels are next to each other by index:

// if score is 10 or more
if (score >= 10)
{
     // if we aren't at the last level
    if (Application.loadedLevel != lastLevel)
    {
        // then load the next level
        Application.LoadLevel(Application.loadedLevel + 1);
    }
    else
    {
        // Game completed!
    }
}
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 Velketor · Mar 08, 2011 at 07:40 PM 0
Share

Hey that code seems to work, but it takes me to a new camera in my current scene ins$$anonymous$$d of loading a new level. I even made sure the layers we included in the Build Settings. Any suggestions? Can it interfere with other scripts? It seems to be conflicting with my player character prefab.

Thanks and I appreciate the response!

avatar image Statement · Mar 08, 2011 at 09:40 PM 0
Share

I doubt it would mess up too much with your other scripts, unless you got something set DontDestroyOnLoad maybe. $$anonymous$$ake sure you've built your scenes so that all game levels are sequential (that level2 is after level1 and so on).

avatar image Velketor · Mar 09, 2011 at 01:11 AM 0
Share

Ya I still can't go from Level 1 to Level 2 when I score points. I am lost, here is my code: var score = 0;

function Update(){ if( score > 4){ Application.LoadLevel(1); }

}

And this is my score script: var cam : GameObject; var Win : GameObject; var Lose : GameObject; var score = 1;

function AddToScore () {

++score;

guiText.text = "Score: " + score.ToString ();

}

function SubtractFromScore(){

--score;

guiText.text = "Score: " + score.ToString ();

}

Any other suggestions? Thank you. I appreciate the help.

Velketor

avatar image Velketor · Mar 09, 2011 at 01:13 AM 0
Share

It's also spawning hundreds audio listeners and I have to re-load Unity.

avatar image Statement · Mar 09, 2011 at 02:25 AM 0
Share

Please place code in your question. It's unreadable in comments. $$anonymous$$ake sure to format it with the code button (I'll do this for you this time). What goes on in your project is out of my comprehension. No code instantiate anything, and you're loading level 1 in your posted code, not any subsequent levels. Be sure to try this out in a separate project to see it's not this code that mess anything up.

avatar image
0

Answer by Safgril · Mar 09, 2011 at 01:47 PM

I am far from an expert. I am new to programming and still trying to figure out how to get my scores to carry over. But i found a cheating quick fix. this will do till you find a better way.

function Update () {

if(playerScore ==2000){

Application.LoadLevel(3);

playerScore = 2001;

}

if(playerScore ==4001){

print("Level 2 complete");

Application.LoadLevel(4);

playerScore = 4002;

}

if(playerScore == 6002){

print("Level 3 complete");

Application.LoadLevel(5);

playerScore = 6003;

}

if(playerScore == 8003){

print("Level 4 complete");

Application.LoadLevel(6);

playerScore = 8004;

}

if(playerScore == 10004){

print("Level 5 complete");

Application.LoadLevel(7);

playerScore = 0;

}

if(playerLives <= 0){

Application.LoadLevel(8);

playerScore = 0;

}

}

function OnGUI(){

GUI.Label(Rect(10,10,200,50), "Score: " + playerScore);

GUI.Label(Rect(10,30,200,50), "Lives: " + playerLives);

}

just adjust the scores to your own levels... and change the load level to what yours are.

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 Statement · Mar 09, 2011 at 02:09 PM 0
Share

Don't feel afraid to answer questions if you are new to program$$anonymous$$g. :) We all start somewhere, and we can all contribute our own thougts and ideas on problems, just like you did. One of the greatest things with answering to questions here is when you realize you're wrong. I have learnt so much from other people correcting my invalid assumptions. And I learn a great deal about other peoples answers. In short; Welcome. :)

avatar image Statement · Mar 09, 2011 at 02:10 PM 0
Share

I just read my own comment and it might sound a bit snappy. I didn't imply your answer is wrong at all. I meant, even a wrong answer yield something good!

avatar image Velketor · Mar 09, 2011 at 03:22 PM 0
Share

I'll try this out tonight and let you know if it works =) Thanks for the help everyone! I appreciate it.

$$anonymous$$

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

Load a random scene from a list of strings. 2 Answers

help please: Level Changing Scipt 1 Answer

FPSPlayer script from FPS tutorial won't work... 0 Answers

linking levels? 2 Answers

Loading Level Async without switching the level immediately 5 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