Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 InfixionGames · Jan 12, 2019 at 08:57 PM · scripting problemscriptable object

How to assign variables to a scene (Solved)

In my game I have a bunch of different levels. In every level you can receive a gem. You can't earn more than 3 gems per lvl. But I don't know how I can implement my system. I have a globalUpgradesManager that never gets destroyed and receives the gems from the levelManager. (eacher level has it's own levelManager)

So when you clear the level the levelManager calls a function in the globalUpgradesManager. This function adds gems based on the health that you finished with on the level. The receiving the gems works. But you can get gems every time you play the level. So instead of getting a max of 3 gems per level you can get as many as you want.

How can I solve this problem? Thank you in advance

Code: public void ReceiveOneGem() { Scene currentScene = SceneManager.GetActiveScene(); string sceneName = currentScene.name;

         if (!levels.Contains(sceneName))
         {
             levels.Add(sceneName);
             //gemsPerLevel.Add(maxGemsPerLevel);
             //maxGemsPerLevel = 0;
             gems++;
             maxGemsPerLevel += 1;
             sceneName = maxGemsPerLevel.ToString();
         }
         else if (levels.Contains(sceneName))
         {
             if (maxGemsPerLevel <= 3)
             {
                 gems++;
                 maxGemsPerLevel += 1;
                 sceneName = maxGemsPerLevel.ToString();
             }
 
         }
         
         }
     public void ReceiveTwoGem()
     {
         Scene currentScene = SceneManager.GetActiveScene();
         string sceneName = currentScene.name;
         if (!levels.Contains(sceneName))
         {
             levels.Add(sceneName);
             //gemsPerLevel.Add(maxGemsPerLevel);
             //maxGemsPerLevel = 0;
             gems += 2;
             maxGemsPerLevel += 2;
             sceneName = maxGemsPerLevel.ToString();
         }
         else if (levels.Contains(sceneName))
         {
             if (maxGemsPerLevel <= 3)
             {
                 gems += 2;
                 maxGemsPerLevel += 2;
                 sceneName = maxGemsPerLevel.ToString();
             }
 
         }
     }
     public void ReceiveThreeGem()
     {
         Scene currentScene = SceneManager.GetActiveScene();
         string sceneName = currentScene.name;
         if (!levels.Contains(sceneName))
         {
             levels.Add(sceneName);
             //gemsPerLevel.Add(maxGemsPerLevel);
             //maxGemsPerLevel = 0;
             gems += 3;
             maxGemsPerLevel += 3;
             sceneName = maxGemsPerLevel.ToString();
         }
         else if (levels.Contains(sceneName))
         {
             if (maxGemsPerLevel <= 3)
             {
                 gems += 3;
                 maxGemsPerLevel += 3;
                 sceneName = maxGemsPerLevel.ToString();
             }
 
         }
     }
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 Klarzahs · Jan 14, 2019 at 09:38 AM 0
Share

A simple way would be to store the currently collected gems per level in a file. Have a look at this website, it explains it quite well. You can then check the leftover gems per level by simply reading from it before you load the level scene.

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by xxmariofer · Jan 14, 2019 at 05:08 PM

Hello, just change your list of names with a dictionary that contains the number of gems you got in that level using the scene name as key. Cant provide know code i will edit this answer in a few minutes.

Comment
Add comment · Show 4 · 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 InfixionGames · Jan 14, 2019 at 05:35 PM 0
Share

Thank you for the respone, I think you showed me the right direction. If you could provide some sample code that would be great

Thanks a lot

avatar image InfixionGames · Jan 14, 2019 at 08:51 PM 0
Share

Thank you xxmariofer, because of you I found the answer to my problem.

You have my gratitude.

avatar image xxmariofer InfixionGames · Jan 14, 2019 at 08:57 PM 0
Share

Hello, glad hearing that, you need any extra help or managed to get it working?

avatar image InfixionGames xxmariofer · Jan 15, 2019 at 09:47 AM 0
Share

It is completely working now thanks to you

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

172 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 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 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 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 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 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 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 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

Get data from Server 0 Answers

Getting an "Enum" value from a Scriptable Object 2 Answers

One Script Referred by Another Script used by Multiple Objects 0 Answers

How to get data from Scriptable Objects without copy-pasting code 1 Answer

Instantiate ScriptableObject with a random asset from List 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