some coding questions regarding a main loop, c# and other stuff

Hi,

we’re planing to create an online configurator tool with unity where users can create theire own stuff like in the “Character Customization” Demo. But before we can start, we’ve some questionts:

  • Is there somehwere a main-loop for the unity game where I can add some special game logic or must all be placed in the special functions/events like onGui etc.?

  • How can I setup the order of the “update” functions which gets called for all gameobjects. For example: I want that alle enemies move first, then all items and after the the player update function should be used.

  • How can I create/call a function wich will be executed every frame regardles wich scene is loaded? I dont want create a “game-logic” object for every scene or something like that…

  • How can I setup the order for the OnGui, and Camera events. For example I want first that the camera rotation/movement is done, then all enemies must be allready moved and after that I want to place some crosshairs around the enemies wich are visible on the camera screen. If the order is not correct the corsshair lags behind by 1 frame or something like that. How would you solve such a problem?

  • Can C#, JavaScript Varaibles/Classes shared between other c# scripts?

  • How can I store certain gameobjects/entites in an array or with a linked-list? For example: I want to acces all enemies at the same time:
    for (i = 0; i < enemy_count; i++) {
    my_enemey = enemies*;*

  • do stuff…*
    }
    * Would C# the right language when developing iPhone games or would you prefer something else?

* How can I use LOD for my gameobjects/entites? I have diffrent models for ech type player_lod1.fbx, player_lod2.fbx, player_lod3.fbx etc.

* I want to make a screenshot and upload the file into a database (BLOB-Field), or on a file server. As I mentioned above we want to use the webbrowser plugin but it seems that a screenhot ist not possible within this mode: Unity - Scripting API: Application.CaptureScreenshot So, how can we do this instead?
http://unity3d.com/support/documentation/ScriptReference/Texture2D.EncodeToPNG.html ?

Could you elaborate. From an OnGUI, you could call functions from lots of places, but they should all be OnGUI type stuff. You could not handle GUI events in the Update function.

Simple, do not run a Update function for ordered objects. Instead run a GameController, which calls each object that is supposed to run in order. (i.e. SendMessage() would work great for this) You will need a register point in the GameController for all objects

Again, the best solution is to create a GameController. Do this all in there.

Again, same, GameController.

Yes, all public variables can be obtained through the GameObject.GetComponent method This holds true until you create your own classes.

I would suggest creating a registration function in your GameController. All units register when they are created. (Start happens before Awake) Then the units work in the timeline based on teh GameController. I would also suggest a check to see if the unit still exists, if not, remove its registration. (sounds eerily like the US government)

I would say yes. I believe that the .Net stuff is probably supported there too.

You could also look into having things linked in your 3d app to have all the lod’s in the same fbx file. They will come in linked as they were in the app. (i.e. player.fbx has lod1 → body → head, lod2 → body → head) LOD’s can still be independent.

I believe that the ReadPixels function is what you are looking for. Read the pixels, put them into a texture file, or send them as raw data to a web page and you can save screen shots as you go.

Thank you very much! That help’s me a lot! :slight_smile: