Post

Code Monkey
Code Monkey@UnityCodeMonkey·
Let's say I saved my game data in a text file and I am now trying to load it, does this work? string savedHealthData = "100"; int healthAmount = savedHealthData; A) Yes B) No C) Yes but healthAmount will be 0 (answer in reply below)
English
6
0
16
4.5K
Code Monkey
Code Monkey@UnityCodeMonkey·
#### ANSWER #### #### ANSWER #### #### ANSWER #### #### ANSWER #### #### ANSWER #### #### ANSWER #### #### ANSWER #### #### ANSWER #### #### ANSWER #### #### ANSWER #### #### ANSWER #### #### ANSWER #### (B) You cannot **implicitly** convert a string into an int. In order to do that you can use the function int.Parse(); or int.TryParse(); int healthAmount = int.Parse(savedHealthData); Or you can use something like JSON to handle the type conversion for you, that's how I normally handle saving and loading in my games and I never have to manually parse numbers. Simple Saving and Loading with JSON to a File youtube.com/watch?v=6uMFEM…
YouTube video
YouTube
English
0
0
6
1.6K
Paylaş