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 shollwedel · Oct 30, 2013 at 03:34 PM · pongscript loading

Loading a new level based on score

I would like to load a new level when the playerScore reaches 20. I've been using if statements followed by load level but they're not working. Could someone take a look at the script and tell me what I should be doing?

Blockquote var cSpeed:float = 10.0; var sFactor:float = 10.0; //Two variables to hold our scores static var playerScore:int = 0; static var enemyScore:int = 0;

function Start () { rigidbody.AddForce(10,1.5,0); }

function Update () { var cvel = rigidbody.velocity; var tvel = cvel.normalized cSpeed; rigidbody.velocity = Vector3.Lerp(cvel,tvel,Time.deltaTime sFactor);

 //Check the right bounds
 if(transform.position.x > 24)
 {
     playerScore++;
     transform.position.x = 0;
     transform.position.y = 0;
 }
 //Check the left bounds
 if(transform.position.x < -24)
 {
     enemyScore++;
     transform.position.x = 0;
     transform.position.y = 0;
 }

}

Comment
Add comment · Show 2
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 Deathdefy · Oct 30, 2013 at 03:49 PM 0
Share

An example of how you were calling Application.LoadLevel() would be helpful as there is no instance in your example. =)

avatar image shollwedel · Oct 30, 2013 at 04:16 PM 0
Share

Sorry, my point was that I don't really know how to go about doing that. I was basically just making stuff up and hoping it would work. the level is called "$$anonymous$$edium $$anonymous$$ode" though

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Stormizin · Oct 30, 2013 at 04:22 PM

 if(playerScore <= 20){
 Application.LoadLevel("level2");
 }

OR

 if(playerScore <= 20){
 Application.LoadLevel(2);
 }

Also see: Application

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 shollwedel · Oct 30, 2013 at 04:37 PM 0
Share

Thanks guys! That's what I was doing, but I keep getting this message: $$anonymous$$ identifier: 'playerScore' But I know that's what the static var is.

avatar image Stormizin · Oct 30, 2013 at 04:50 PM 0
Share

If any answer helped you please mark it to an answer of this question to keep the community organized.

avatar image shollwedel · Oct 30, 2013 at 04:55 PM 0
Share

I will, just nothing has worked yet and I can't figure out why

avatar image
0

Answer by Deathdefy · Oct 30, 2013 at 04:27 PM

So you definitely have the right idea. The only thing is to make sure that you have the levels loaded into the build settings. To do this if you haven't already File->Build Settings then ensure that all levels are added.

There are two ways to load a level. One by index and the other by string as you just provided. Obviously make sure that the string matches 100% otherwise it will not load. So in your case....

 if(playerScore <= 20){
 Application.LoadLevel("Medium Mode");
 }
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

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

Related Questions

How to move a object side to side using mouse? js3 0 Answers

How to freeze movement on X-axis. (See Comments for Update) 2 Answers

Master Server and Faciliator connection 0 Answers

Unity pong online multiplayer 0 Answers

Can you help me with my loading screen 0 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