Hello, I'm wondering if I have one to many lines of code in my Void Update. Theirs 300 lines of code with only this repeated 30 times.Seems like it would kill the IOS/Android device. Code (csharp): void Update(){ if (my item){ PlayerPrefs.GetString("item", item ); bool = false; } }
You shouldn't read from or write to PlayerPrefs in Update without any proper control. It seems that some of your conditions are permanently true. Load the values once, cache them in variables and save them when needed.
No one is going to steal your wonderful idea. But there are plenty if better ways to code this then repeating the same code 30 times over. For a starter use a loop. There is very little point to accessing player prefs in update. I would suggest loading all of the variables once into an array. Then reference the array data. When it's time to exit save the data back to player prefs.
Make a data manager with a singleton, and event delegets , data stream should never be in update, as boredmormon stated here also.
So you want us to provide you with code and help for your own personal gain, but won't share your "wonderful" idea with us? That's pretty scummy mate.
You could put 3000 lines in and it will still run better than accessing playerprefs in update. You want a bottle neck? because thats what you made. I think you could improve it with this code... Code (csharp): void Update(){ while(true) { if (my item){ PlayerPrefs.GetString("item", item ); bool = false; } } }
The number of lines of code is irrelevant to performance. One slow call can do for more damage to performance then 50,000 fast calls. Several competent people have suggested that a more intelligent data structure could improve performance. I suggest you consider their advice. And finally, when it comes to performance, the profiler is always the answer.
i do. Code (csharp): if(Z15 == true) { PlayerPrefs.SetInt("QuestionNumber", Question108); Z15 = false; Z100 = true; Z98 = true; } Basically it just starts with one and when someone chooses a option it goes to the 2 other options and saves the players position in the level. their 100's of questions which is why I have so many lines. Thanks for all the help.