Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 secretsecret · Jul 15, 2013 at 09:53 AM · static variables

Reset static variables

How can I reset a static variable? For my game i have a reset button however it does not reset my static variable. my static variable is:

public static int Score = 0;

and it is being called at:

void OnCollisionEnter() { Destroy(gameObject); Player.Score += 100; } }

Comment
Add comment · Show 4
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 BiG · Jul 15, 2013 at 09:54 AM 0
Share

You should first modify your variable and then destroy the object itself. However, it doesn't seem that the variable is been resetted, but incremented by 100.

avatar image secretsecret · Jul 15, 2013 at 09:58 AM 0
Share

It increases the score by 100 each time you hit a enemy. and one you die i made a reset button but when the reset button is hit it wont reset the score.

avatar image BiG · Jul 15, 2013 at 10:02 AM 0
Share

So you should post that specific part of code, this doesn't seem too much to help.

avatar image secretsecret · Jul 15, 2013 at 10:17 AM 0
Share

using UnityEngine; using System.Collections;

public class restart : $$anonymous$$onoBehaviour {

 // Use this for initialization
 void Start () {
 
 }
 
 // Update is called once per frame
 void Update () {
     if (Input.Get$$anonymous$$eyDown ($$anonymous$$eyCode.R)) 
     {
         Application.LoadLevel ("Cube Game");
     }
 }

}

// this script helps restart the game when the R key is presed. // this alows the player to get right back into the action of the gamme instantly // is not reseting static variavbles though. // this may be resolved with another scrip.

Does that help?

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by BiG · Jul 15, 2013 at 10:32 AM

OK, this two answers should point you to the right direction with ease:

http://answers.unity3d.com/questions/180515/applicationloadlevel-not-resetting.html

http://answers.unity3d.com/questions/36152/reset-a-static-variable.html

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 secretsecret · Jul 15, 2013 at 12:02 PM 0
Share

It would be nice if I could get the first example in C# and not java. http://answers.unity3d.com/questions/180515/applicationloadlevel-not-resetting.html

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

16 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

Related Questions

Static variables and Design Fundamentals (singleton) 1 Answer

how to keep static variables or 2d array value 0 Answers

Static Variables 2 Answers

Multiple GameObjects accessing the same script, when script destroys game object, it destroys it across all the GameObjects 1 Answer

Using variables and classes of C# in Javascript? 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