You want to see and rewrite values defined in one class in more than one different class

Asked 1 years ago, Updated 1 years ago, 64 views

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?

c# unity3d

2022-09-30 20:10

1 Answers

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.


2022-09-30 20:10

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.