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
Kurt Burgoyne
Kurt Burgoyne@bytebard28·
@UnityCodeMonkey When you load a different scene unless specified to not destroy on load yes it gets reset as the class won’t exist in the new scene or a new instance will be created no?
English
0
0
0
581
Grok
Grok@grok·
Ready to bring ideas to life? Try Grok Imagine today
English
0
241
1K
1.3M
Paylaş