This is Unity's C#.
public class A {
public int[]tmp = new int[3] {1,2,3}
}
class called
public class AddScript:MonoBehavior {
Aa = new A();
void Start() {
a.tmp[0]++;
}
When called by Script attached to GameObject (prefabbed and multiple-regenerated), tmp is initialized each time a GameObject is generated, and tmp[0] remains at 1.
How do I increase the value of tmp[0] each time it is generated?
It was solved by referring to it as static.
This post was edited based on @ShrimpUdon's Comment and posted as Community Wiki.
This post was edited based on Comments by @ShrimpUdon, and posted as Community Wiki.
© 2025 OneMinuteCode. All rights reserved.