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 SirBoboHobo · Apr 10, 2015 at 09:35 PM · c#dontdestroyonloadcount

death count resets after re-loading scene

deahtAds script:

public int death;

     private static readonly Dictionary <String, String> REVMOB_APP_IDS = new Dictionary <String, String>() {
         }
     };
     private RevMob revmob;
     private RevMobFullscreen fullscreen;
     // Use this for initialization
     void Awake () {
         DontDestroyOnLoad (this);
         revmob = RevMob.Start(REVMOB_APP_IDS, "Ads");
 
     }
     void Start(){
 
         #if UNITY_ANDROID
         RevMobBanner banner = revmob.CreateBanner(RevMob.Position.BOTTOM, 0, 0, Screen.width, 100);
         banner.Show ();
         #elif UNITY_IPHONE
         banner = revmob.CreateBanner(0, 0, 350, 50, null, null);
         banner.Show();
         #endif
 
     }
     // Update is called once per frame
     void Update () {
         Debug.Log (death);
         if (death > 2) {
             death = 0;
             revmob.ShowFullscreen();
         }
     }
 
 }

and in my main character script, when the player dies it supposed to add + 1 to public int death, and when gets to 3 show an ad and reset itself. this is how i add:

 deathscript.death +=  1;
 

in awake function im getting the script deathAds. even tho im using dontdestroyonload, it still does destroy it, and begins the count all over again.

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 rob5300 · Apr 11, 2015 at 10:51 AM 0
Share

What script has this Awake function that is refencing the deathAds script?

How are you reloading the scene?

Also the deathAds needs to have in awake/start DontDestroyOnLoad too. $$anonymous$$ake sure to pass the reference to the gameobject it is attached to!

avatar image DoTA_KAMIKADzE · Apr 11, 2015 at 11:10 AM 0
Share

I don't think that SirBobo really need DontDestroyOnLoad here anyway, for just saving death count static variable is a better idea along with removal of "incorrectly coded" Line#8, unless that is needed for Rev$$anonymous$$ob.

P.S. Though I guess if script holder is a player then it gets destroyed anyway on death (if player is), in that case that won't work even if Rev$$anonymous$$ob needed it.

1 Reply

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

Answer by DoTA_KAMIKADzE · Apr 10, 2015 at 09:51 PM

public static int death;

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 SirBoboHobo · Apr 11, 2015 at 10:35 AM 0
Share

I've tried this before, the problem is that I get an error since im trying to call a static variable in a different script, I can't use get component,and i dont really know how to get static variable.

avatar image DoTA_KAMIKADzE · Apr 11, 2015 at 10:45 AM 0
Share

You don't need to call it using instance of your class, just:

 ClassName.VariableName;

In your case it should be:

 deahtAds.death += 1;//if from another script
 //or if from same you can do as this as well:
 death += 1;
avatar image SirBoboHobo · Apr 11, 2015 at 12:40 PM 0
Share

Thanks, Been trying to solve this for a while now!

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

20 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

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Setting public GameObject to a different Prefab through code 0 Answers

Get the amout of objects in a given position 1 Answer

Enum Count 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