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 /
This question was closed Jul 03, 2017 at 10:23 PM by JimmyCushnie for the following reason:

I don't even know what my question is at this point. I'm going to try to fix it myself.

avatar image
0
Question by JimmyCushnie · Jul 03, 2017 at 09:56 PM · intinteger

How do I increase an integer??

 public int TestInt;
 
 public void Update()
     {
         TestInt += 1;
     }

This should increase TestInt by 1 every frame, right? But in the inspector, it stays at zero :( Am I doing something incorrectly? Do I have a misunderstanding of how the inspector works?

EDIT: I found the issue. My script was attached to a prefab rather than a gameobject. Like an idiot, I was looking at the value of the int by inspecting the prefab rather than the gameobject created when the prefab was initialized.

Edit2: and I resolved the issue be storing the int as a value in another script attached to another gameobject, then copying those values to the prefab upon initialization. Hope this helps somebody.

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

3 Replies

  • Sort: 
avatar image
0

Answer by Mergster · Jul 03, 2017 at 10:00 PM

You could do

 TestInt ++;

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 JimmyCushnie · Jul 03, 2017 at 10:16 PM 0
Share

This isn't working for me either.

avatar image Mergster JimmyCushnie · Jul 03, 2017 at 10:19 PM 0
Share

Is this script applied correctly on a gameobject in the screen?

avatar image JimmyCushnie Mergster · Jul 03, 2017 at 10:41 PM 0
Share

Yes. I can change the int in the inspector just fine, but for some reason I can't use code to change it on this particular script. Everything works as expected on other scripts, I suspect I've borked this one in some way.

avatar image
0

Answer by Bunny83 · Jul 03, 2017 at 10:01 PM

This should work just fine. Just make sure you don't have the edit field in the inspector selected. When you select / click into the edit field the current value is copied into the string editor. Since you can now edit the value it isn't updated anymore until the field is deselected.

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 JimmyCushnie · Jul 03, 2017 at 10:17 PM 0
Share

No, I do not have the edit field selected.

avatar image
0

Answer by JimmyCushnie · Jul 03, 2017 at 10:22 PM

Okay so actually it does work if I put it on a new script. I just can't increase (or change at all, it seems) the identically coded integers in my own script.

Comment
Add comment · Show 2 · 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 TheDJBuntin · Jul 03, 2017 at 10:45 PM 0
Share

Is it maybe because you put "public void Update()". Should be void Update() - not sure if that makes a difference though.

avatar image JimmyCushnie TheDJBuntin · Jul 03, 2017 at 10:49 PM 0
Share

I was using "public void Update()". I fixed it but the issue persists :(

Follow this Question

Answers Answers and Comments

68 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

Related Questions

UI system multiple ints as function arguments 4 Answers

Divisible by 3 2 Answers

PlayerPrefs setting to an existing int 0 Answers

Checking to see if a loaded level is equal to a member of an integer array 1 Answer

Problem with changing animations using int values 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