- Home /
I don't even know what my question is at this point. I'm going to try to fix it myself.
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.
Answer by Mergster · Jul 03, 2017 at 10:00 PM
You could do
TestInt ++;
Is this script applied correctly on a gameobject in the screen?
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.
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.
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.
Is it maybe because you put "public void Update()". Should be void Update() - not sure if that makes a difference though.
I was using "public void Update()". I fixed it but the issue persists :(