mardi 7 février 2017

Unity - Accessing other scripts' variables - put properly

I know how to access another script's variable, but I can do only via function calls or delegates. The first one is easy, but makes the code fragile becuase once I edit the original, I have to edit again. The second one is better but as I have a lot of functions, with different kinds of return values and parameters, it would complicate things a lot. Say I want to do some stuff at the beginning of the game. So far I created a function named OnGameStart() in the appropriate script and called everything I will need from there, and that OnGameStart() was made public and was called from another script.

I will need to play sounds, check save data, play UI and other animations and so on at the beginning but I don't want to make my code a disaster. I looked for this online but found only the simplest "how to communicate between scripts" stuff, which goes with the basic function call, sometimes events. Could someone skilled guide me to resources on how to make compact, segregated classes that hold up Demeter's law?

Aucun commentaire:

Enregistrer un commentaire