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 john 2 · Aug 17, 2010 at 09:45 AM · levelloadlevelresetmainmenu

reset the level?

after my character dies he goes back to the main menu(for now) but when i hit play game it just flashes up the level for just a second when i press it. when i hit play game when i start the game it is fine. i'm assuming that it has to do with the level being destroyed after i go to another level.so could someone please explain how to "reset a level"?

My main menu text script:

var isQuitButton = false;

function OnMouseEnter() { //change txt color

 renderer.material.color = Color.gray;

}

function OnMouseExit() { //change txt color

 renderer.material.color = Color.white;

}

function OnMouseUp() { //are we dealing w/ quit button

 if(isQuitButton)
 {
     //quit the game

     Application.Quit();
 }   
 else
 {
     //loadlevel

     Application.LoadLevel(1);
 }

}

Comment
Add comment · Show 1
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 spinaljack · Aug 17, 2010 at 10:22 AM 0
Share

Are you using a tutorial? You've probably missed a step. Try Application.LoadLevel(Application.loadedLevel);

5 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Bampf · Sep 15, 2010 at 01:21 PM

I'm guessing that when the game starts again, it "remembers" the fact that the game was quit. In other words, the level is loading but whatever condition caused it to end in the first place is still true.

Are you using DontDestroyOnLoad anywhere? That's often used to pass information from one level to the next, such as how many lives the player has left. But when starting a new game you will need to set the number of lives back to 3, score back to zero, etc.

There are other ways to keep information around across levels, such as PlayerPrefs, or writing the data to a file. Whatever you are using, you will need to reset it before starting a new game.

Do you have any static variables? Same issue. Here's a link to a Q&A for a problem very similar to yours, that was caused by static variables.

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 vdizzle · Aug 17, 2010 at 03:42 PM

I had the same issue yesterday with my level only flash not even a sec. Its your code. Are you using a platform controller script? I did not destroy the level after i complete each or after I have died. What function do you have after the user die in you death()? Make sure you create an if then statement then load the new scene. I thought it was something far complicated but it was just the code....

so say after 3 deaths your end user have to go back to the main menu. Also you may have code in two errors....thats what my problem was. I had code in the death() in the platform controller script and also in the guitext script that controlled the amount of lives.

code
////// if (lives== 3){ Application.loadLevel(1); } }

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 vdizzle · Aug 18, 2010 at 12:53 AM

I think its your code. Why dont you just do this. Create a new js file. Then for your two buttons You have a quit button and then a restart button. hopefully your using GUITEXTURES--samething applies with GUITEXT

So you can break these off into 2 separate scripts and attach each to each button.

////////////////////////////////////script 1 attached to the restart btn

var btnA:GUITexture;///this is the Quit Button

function OnMouseDown(){

btnA.enabled=true;

Application.LoadLevel(1); }

///////////////////////////////////

script 2 attached to the quit button

var btnB:GUITexture;//this can be the restart button

function OnMouseDown(){

btnB.enabled=true;

Application.Quit(); }

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 john 2 · Aug 18, 2010 at 11:34 AM 0
Share

that didn't work because i don't have anything to attach to the GUITextures. somebody please help me!

avatar image
0

Answer by phillywassupp · Dec 12, 2010 at 05:43 PM

Hey i am having the same problem, My game works well moving to the levels but then when the player dies it loads a new scene with two buttons one which reverts to the first level and one which goes to the main menu but even when you play the first level again it just does the 1 second die thing.

Did you use the tutorials by tornado twins by any chance? i think it could be something to do with the health control as its not scene specific and isn't resetting at the start of the level.

if you figure it out i would love to know!

Hey i figured it out!!

mine works perfectly now all i had to do was reset the static variable on awake using this code:

static var LIVES :int ;

private var LIVESInt = 3;

function Awake () { LIVES = LIVESInt; }

hope it works for you

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 Mc.Lover · Sep 02, 2011 at 01:55 PM 0
Share

Sorry your code does not work for me !!! ' function On$$anonymous$$ouseUp () {

     Application.LoadLevel(0);
 

}

static var LIVES :int ; private var LIVESInt = 3;

function Awake () {

  LIVES = LIVESInt;

}'

avatar image
0

Answer by GXVIII · Nov 19, 2012 at 08:56 PM

Well seeing as how it is a pain to have everything reset itself. I will be creating a transition scene. You can save your current scene name (the one being reset) in a playerpref, move to the transition scene, then from the transition scene have it load the saved playerpref level name. This may seem a bit much but loading a scene with a static loading backdrop then loading the original scene seems a lot easier. Whenever I load a new scene then load the one I want reset it seems to load fresh. However this will not fix issues with DontDestroyOnLoad objects.

Just tested my code and approach and is working flawlessly for me.

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

2 People are following this question.

avatar image avatar image

Related Questions

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

"Reset Level", Application.LoadLevel 1 Answer

My GUITexture Script doesn't re-activate when reloading a level. 3 Answers

Door that changes level on character collision script help? 1 Answer

Level advancment Scirpt 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