Hi,
Now I’ve got to grips with the basics of coding in UnityScript and had a lot of fun putting a game together, now that I am enjoying myself when coding and getting results, I find myself really keen to start making my UnityScript more efficient. Usually I pretty much have everything running in the Update Function as the game is quite simple. I know this is inefficient as not everything needs to be calculated every frame. So, here are my questions:
- MonoBehaviour.InvokeRepeating - Some functions I need to run say once a second straight from the start and all the time. Is this the best way to do it?
- Coroutines (Part 1) - For other functions that need to be run once a second but is only used a few times, is a Coroutine with a yield function the best way to do it?
- Coroutines (Part 2) - Is calling coroutines from the Update function the best way to call them. I know how to check if a coroutine is still running using a boolean but is there a more efficient way that I am not aware of?
- Re-Cycling Scripts - Does this actually have an impact on CPU useage? I know it makes for more efficient coding but would this make the game run faster, especially if there are large number of objects using the same script?
- Caching variables - I have heard this is more efficient in cases such as GameObject.Find. So should I create a script that finds the game object once and share it as a static variable with all the other scripts that need to find it? Or should I cache it just locally in the script. Around 200 to 300 objects will be using it if that puts it into perspective.
I am also wondering if I have missed any good video tutorials or general guides WITH EXAMPLES that someone may be aware of. I struggle with just reading theory and need to practice with examples.
Thanks!
Paul