- Home /
Running most code in one script?
Hello, I'm making a block based game, but I'm not putting Update() in my block script due to the fact that there will be so many blocks, and I don't want that many if-statements and such to be running sixty times a second for each block, so I'm doing all the updating code for the blocks in the player script but storing variables and methods in the block script . Would it make sense to continue doing this? It doesn't seem right that I'm doing checks to see if a block has broken in the player script, among other things, but it also doesn't seem right to run code in thousands of different objects at the same time.
Answer by Cynikal · Apr 05, 2018 at 07:44 PM
Having a "master" resource is the most acceptable way of doing something like this. It's best to think of your blocks as event based. So, normally, they do nothing. However, when they break, then they'll react.
What breaks the blocks? Have whatever breaks it as the thing that sends out the event... Or even if the block itself is what knows if it breaks, then have it send out an event to the main listener (master)
That sounds like what I'm doing currently, the player is calling an event in the block script to break the block, and how much resources does an if statement itself cost? Such as if I needed to have a grass block spread to another block based on chance every frame.
//Example
if (Random.Range(1, 10000) == 10000){
}
Your answer
Follow this Question
Related Questions
How to update local(cache) texture? 0 Answers
Best method to save states in/for a prefab 0 Answers
future updates 0 Answers
[2D] Get the position of an object outside the scope 2 Answers
I think I abuse of Ressources.load 2 Answers