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 montedre · Sep 14, 2012 at 12:09 AM · levelresetvar

Help with loading new levels - restarting scripts

I have created the start and first level of a game. I would like to add several more levels to the game but need some help. The game is a simple shooter game that I should be able to reuse almost all the scripts in the subsequent levels but I need then to reset. Is this possible and if so how do I do such a thing. Also is it possible to set the var in the scripts different for each level without using a copy of the script. Please let me know what I need to post if you do not understand the question.

Thanks

Monte

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 montedre · Sep 17, 2012 at 06:57 PM 0
Share

Thanks for the help guys. I think I understand. I made an exact copy of level one by duplicating it and when I loaded level two all it loaded as if all ready played. In other words exactly like level one finished. I hope that makes sense. So if the scripts reset why would that happen?

avatar image montedre · Sep 17, 2012 at 07:00 PM 0
Share

Ok guys I think I have tried everything I know how to do at my early stage of learning. The scripts are not resetting. If I understand it right I should be able to make an exact duplicate of level one as level two and it should work. but all my UI is staying exactly as it ends in level one. The new scene is loading with all the old information in the UI. Again I can post what ever would help or the whole game as a zip if that is what you need.

Any help would be greatly Appreciated.

$$anonymous$$onte

4 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Kirbyrawr · Sep 14, 2012 at 02:27 PM

The scripts resets when you change to another scene , what's your problem?

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 Kryptos · Sep 14, 2012 at 03:04 PM 0
Share

Just to make it clear: the scripts themselves do not reset. But the GameObject on a scene are reloaded setting their components back to the original state stored in the scene file.

avatar image
0

Answer by ChrisAllen · Sep 14, 2012 at 02:33 PM

the script will reset if you're loading them into another scene, unless you are using doNotDestroyOnLoad().

On your second point. If you declare the variables you want to change outside of your Update() function (usually at the very top of the script),they will appear in the inspector for the object they are attached to. Then you can change the variable values in the inspector and it will only affect that particular game object.

so your script would look like this

 var levelNumber : int;
 var health      : int;
 var numberEnemies : int;
 
 function Update()
 {
    //your update scripts here
 }

Then in the inspector you will have some options in the script component called

Level Number

Health

Number Of Enemies

you can reuse the same script in each level setting these variables throught the inspector (you can set the values of the variables in the script but the inspector version overwrites whatever is in the actual script when you run the game)

I hope this makes some sort of sense, and helps you out

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 Kryptos · Sep 14, 2012 at 03:01 PM

Put the script on different prefab and use one prefab per scene.

Or create a unique prefab, add an instance of this prefab in each scene and override their value in the Inspector like @chrisallen suggested.

One way or the other, you don't need to copy/paste your script.

Comment
Add comment · Show 2 · 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 montedre · Sep 14, 2012 at 03:56 PM 0
Share

Just to be clear you are saying use the same script and a different prefab. so Copy the prefab then but the same script on it and I can change the values in the inspector. so the script becomes an instance of the prefab and therefore does not effect the uses of the script.

I assume then the prefab should not be created with the script already attached?

thanks

$$anonymous$$onte

avatar image ChrisAllen · Sep 14, 2012 at 04:29 PM 0
Share

you can attach the script to the prefab, but you will need to change the inspector variables for each instance of that object (when you drag the prefab into your scene)

avatar image
0

Answer by montedre · Sep 14, 2012 at 04:25 PM

Thanks for the help guys. I think I understand. I made an exact copy of level one by duplicating it and when I loaded level two all it loaded as if all ready played. In other words exactly like level one finished. I hope that makes sense. So if the scripts reset why would that happen?

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

12 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

Related Questions

"Reset Level", Application.LoadLevel 1 Answer

How to Reset Scene after Level Completion 1 Answer

reset the level? 5 Answers

How to reset a level by collecting items?!?! 3 Answers

How can I reset my level when the player walks on a specific floor in the game? 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