Post

Code Monkey
Code Monkey@UnityCodeMonkey·
Does this variable get reset when you load a different Scene? private static int score; A) Yes B) No C) Only when loading the Main Menu (answer in reply below)
English
3
1
19
7.1K
Code Monkey
Code Monkey@UnityCodeMonkey·
#### ANSWER #### #### ANSWER #### #### ANSWER #### #### ANSWER #### #### ANSWER #### #### ANSWER #### #### ANSWER #### #### ANSWER #### #### ANSWER #### #### ANSWER #### #### ANSWER #### #### ANSWER #### (B) Static variables only get initialized the first time the class is used. If you load a different Scene, like reloading your Main Menu to start playing from the beginning, you need to manually reset your static variables or they will carry over with the same value. Alternatively this is also an easy way to intenationally pass data between Scenes.
English
1
0
17
1.3K
AnEmortalKid 🦝 🦝
AnEmortalKid 🦝 🦝@AnEmortalKid·
@UnityCodeMonkey Ah but this won’t work with game object references since those get destroyed so your reference will be set but to a null style / not valid object right ?
English
1
0
0
104
Paylaş