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 nightbane30 · Feb 26, 2014 at 10:17 PM · guiscoredontdestroyonloadlives

DontDestroyOnLoad Game Score/Lives

Hello everyone. I'm creating a space shooter game and I'd like the score and lives to carry over into the next scene of the game. I thought you would use the DontDestroyOnLoad method, but it seems to be having issues. I have my GUI script display for the Lives/Score counter attached to my Main Camera but carrying that over into a new scene freezes the game. Here is my GUI script attached to the Main Camera:

 using UnityEngine;
 using System.Collections;
 
 public class MyGUI : MonoBehaviour {
 
     public string nextlevel;
 
     // Use this for initialization
     void Start () {
     
     }
     
     // Update is called once per frame
     void Update () {
         if (Player.score == 50) {
             Application.LoadLevel(nextlevel);
                 }
     
     }
     void OnGUI () {
 
 
         GUI.Box (new Rect (1700, 25, 300, 100), "Score : " + Player.score + "  Lives: " + Player.playerlives);
 
 
     }
 }

Can anyone help with this?

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Oniony · Feb 27, 2014 at 02:34 AM

Hmm I'm not sure if this would work but when Player.score == 50 you can set the score to a playerprefs variable and then in the next scene in the start method just reload the player.score from the playerpref.

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 nightbane30 · Feb 28, 2014 at 11:39 PM 0
Share

Hmm...would playerprefs really be a good choice for just carrying over lives and such? I mean, I heard that it's more for saving positions in an RPG game or saving long-term data. $$anonymous$$y game is just a space shooter where I want the lives to continue carrying from the last scene.

avatar image nightbane30 · Mar 01, 2014 at 12:03 AM 0
Share

Solved! I just created an empty gObj, stored a script in it with the playerlives and score variables as public and static, then used the DontDestroyOnLoad method in there. TY for the help, though!

avatar image nightbane30 · Mar 13, 2014 at 12:24 AM 0
Share

Static didn't work anymore O_O

I posted a new question dealing with GetComponent.

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

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

Related Questions

Scoring with positions 1 Answer

GUI Text Score counter 3 Answers

Help! Why doesn't this work? GUI/Static vars Help! Javascript 1 Answer

Coin Counting Problem 0 Answers

DontDestroyOnLoad reset the gameobject 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