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 Velketor · Mar 07, 2011 at 05:10 AM · gameloadlevelend

how do you actually stop a game?

I've got level 1 finished and I'm trying to end Level 1 and start Level 2...how do I do that? I don't know how to end my game. Is there a special script or technique for ending a game...or moving up a level?

When the player gets 10 points, the level should take the player from level 1 to level 2.

or

If time runs out, restart the current level. I had no internet all weekend so I tried everything I could with what Unity comes with. Made it far, but really need a place like this to ask the questions so my game can finish!

Please let me know. Much Appreciated +_+ Thanks!

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

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Tyler Starr · Mar 07, 2011 at 05:23 AM

Use a point system such as:

var score = 0; var scoreText = "Score: 0"; var mySkin : GUISkin;

function OnTriggerEnter( other : Collider ) { Debug.Log("OnTriggerEnter() was called"); if (other.tag == "Asteroid") { Debug.Log("Other object is a coin"); score += 25; scoreText = "Damage%: " + score; Debug.Log("Score is now " + score); Destroy(other.gameObject); GameObject.Find("Main Camera").animation.Play(); } }

function OnGUI () { GUI.skin = mySkin; GUI.Label (Rect (100, 10, 500, 200), scoreText.ToString()); }

 function Update(){
     if( score == 100){
         Application.LoadLevel(0);
     }
 }

The Script counts (damage or Points) then:

if( score == 100){

sees if my score or damage in this case is 100 (score is a number variable).

Now that the script or your score script sees that the score is 100 or what ever you set it to it uses:

Application.LoadLevel(0);

Application.LoadLevel loads level that is defined as number 0 in the player settings(0 can be change to level you want). Then it loads the level defined by the number(0 in my case).

-Hope this helps. Comment if you need anymore help or explanation.

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 Sriram · Mar 07, 2011 at 05:30 AM

First thing you need to do is go to, File->Build Settings and add all your levels there so you can switch in between levels.

Now, say your playing level 1 and time tuns out, you could do something like,

if(time<=0)
Application.LoadLevel("1");

Similarly if the player completes the level on time and you want to switch to level 2, you would do Application.LoadLevel("2");

To quit an application, say end game,you would do something like, Application.Quit();

For more information on using these methods, check out this link

http://unity3d.com/support/documentation/ScriptReference/Application.html

Hope this helps

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 anomalous_underdog · Mar 07, 2011 at 05:41 AM

Create your Level 2 as a new scene, save it. Add the scene of Level 1 and 2 to the Build Settings. (File > Build Settings... > Add Current) Make sure they are in the order you want them to be (Level 1 is at the top, Level 2 is below). Drag and drop entries in the list "Scenes in Build" to change the order.

Put the script below in any game object in Level 1.

Change the value of score everytime the player gains points. Change levelTime to the number of seconds the timer should be in.

var levelTime = 10.0; var score = 0;

function Start() { Invoke("GoToNextLevel", levelTime); }

function GoToNextLevel() { Application.LoadLevel(Application.loadedLevel+1); }

function Update() { if (score >= 10) { GoToNextLevel(); } }

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 07, 2011 at 02:35 PM 0
Share

Thanks everyone, I'll be testing it tonight and will let you know how it comes out! I appreciate the answers. Velketor

avatar image Velketor · Mar 09, 2011 at 02:49 AM 0
Share

none of them worked :/ not sure what im doing wrong, been trying for hours now. hmmm...

avatar image anomalous_underdog · Mar 09, 2011 at 06:45 AM 0
Share

@Velketor: explain the situation. do you get error messages?

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

No error messages. It just doesn't seem to be able to find score. I'm confused :/

avatar image anomalous_underdog · Mar 10, 2011 at 04:05 PM 0
Share

How are you trying to add score to the player? Post all your relevant code in the question. Is the level at least changing once the time runs out?

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

Problems with script 1 Answer

Loading a level on contact 2 Answers

Load Level when Key is pressed 2 Answers

level loader script wont work 1 Answer

End game then an Object is close to another object? 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