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 07, 2015 at 04:50 PM · c#adscounterreload

not resetting the death count on reload

I have a death counter that each 3 deaths the death resets to 0 and a revmob ad is displayed. but when i reset the level the death count also resets, i tried making it static but it keeps counting after 3 and doesn't resets. I thought using PlayerPref but I'm not sure how efficient that is and I didn't test it, can somebody shed a light upon my problem?

                 private int death;
                 death ++;
         Debug.Log (death);
         if (death == 3) {
             revmob.ShowFullscreen ();
             death = 0;
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

5 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by raulrsd · Apr 07, 2015 at 07:35 PM

The solution is to make it static, if you say that it didn't reset when you tried it, you should force the reset in any start() method (or in your resetLevel() method, if it exists). I suggest you make a static class called GlobalVariables and inside this class put the public static int numOfDeaths. Then you could access it from any script this way:

 GlobalVariables.numOfDeaths = 0;
 GlobalVariables.numOfDeaths++;

or whatever

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 winsjansen · Apr 07, 2015 at 10:21 PM 0
Share

You don't need to use static for this, nor is that possible as it seems you want your attribute private(?) + as it seems you want this attribute in the same class, or am I wrong?

I'm pretty sure it is because of your ad pausing the method and or not returning to it properly.

Have you tried resetting the death before you play the advertisment?

Also, you state in your question both that the attribute DON'T reset, and that it DOES, what do you really mean and more importantly what are you trying to do? :)

PlayerPrefs is by far any inefficient way of storing attributes on phones, btw. You can definitely use it for things like this with no problem.

avatar image SirBoboHobo · Apr 07, 2015 at 11:23 PM 0
Share

$$anonymous$$y game starts, play play play, character dies, death count = 1 restart the game, play play play, character die, death count = 1. its resets itself as the scene does too, i want the death count to stay 1 even after it reloaded, and be 2 when died, at 3 deaths display the ad and make the variable count from 0, endless loop.

avatar image raulrsd · Apr 08, 2015 at 08:01 AM 0
Share

When you say "restart the game", do you mean: "reload the scene"? If the answer is yes, the easiest way is what I said in my previous answer. If you don't like it, or you can't make it work, explain us what is happening and we'll try another way.

avatar image
0

Answer by piacentini · Apr 08, 2015 at 09:21 AM

The problem is that the variable is private from the class. It is created again when the class is recreated, so it will always have the same value. You need something like a gamestate singleton that survives your reloads of the levels. Here is a nice article showing you how to implement it:

http://www.fizixstudios.com/labs/do/view/id/unity-game-state-manager

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 Arju2011 · Apr 08, 2015 at 09:23 AM

You said "it keeps counting after 3"

  public int death;
          death += 1;
          Debug.Log (death);
          if (death > 2) {
              revmob.ShowFullscreen ();
              death = 0;

Try this, and if it doesn't work, then I don't know.

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 08, 2015 at 12:43 PM 0
Share

it keeps counting after 3 if i make it static, "i tried making it static but it keeps counting after 3 and doesn't resets" I'm looking for a way it'll count to 3 show ad and reset the count, static makes it count after 3 and reloading the scene resets the variable death back to 2

avatar image Arju2011 · Apr 08, 2015 at 05:43 PM 0
Share

Did you try making it public as others have suggested?

avatar image SirBoboHobo · Apr 08, 2015 at 06:19 PM 0
Share

yes, it is public. I thought about maybe attaching the death count to a gameobject in the scene and using DontDestroyOnLoad method, but that seems to me like a waste of resources and making things messy.

avatar image
0

Answer by Luka-L · Mar 04, 2017 at 09:15 AM

@SirBoboHobo make death int static (You can exclude [SerializeField] and make int public)

 [SerializeField]
 private static int deathCount;

Are you sure you're placing code below in void Update?

 void Update () {
     if (deathCount == 3){
      deathCount = 0;
   }
 }

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 eshedye · Jan 19, 2018 at 08:19 PM

u just need on your public int to mention its zero:

public int Deaths = 0;

void Update () { if (Deaths>=4f) { Deaths = 0; } }

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

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

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Renderer on object disabled after level reload 1 Answer

Admob Rewarded video and Different APK size in Alpha testing 0 Answers

Why is Unity Ads not showing an ad in unity 5.2? 5 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