Search Unity

Basic questions

Discussion in 'Scripting' started by BusyRobot, Jan 4, 2014.

  1. BusyRobot

    BusyRobot

    Joined:
    Feb 22, 2013
    Posts:
    148
    I'm still trying to wrap my head around how you script with Unity.

    So am I to understand correctly that all the code that runs, runs asynchronously? so you attach some code to various elements on the screen, and they run independent of each other? but then how do they communicate between each other? and in that case there's no central thread/singleton which everything runs through?

    And how would be say coding with Futile be different than coding with Unity straight?
     
  2. LightStriker

    LightStriker

    Joined:
    Aug 3, 2013
    Posts:
    2,717
    No idea about Futile, sorry.

    For Unity, there's one main single thread that update every Script one after the other. Order in which they are update is random unless you force specific script type to have priority over others. Communication between object is totally up to you. You can link object using the Inspector, or you can retrieve an instance at runtime, or you can even create or instanciate one yourself.
     
  3. MDragon

    MDragon

    Joined:
    Dec 26, 2013
    Posts:
    329
    For inter-communication... (there's probably a better word for it but this is the best I got)

    Variables between scripts are pretty much independent of one another; although they may be "public" and accessible in the Inspector, you can't simple use that same variable name (and associated value) in another script. HOWEVER, there are quite a few ways to access other scripts' functions and variables, so that it works pretty seamlessly.

    A primary way to make two objects affect each other is to declare a public variable of type GameObject (or Transform or anything else). That object and it's associated properties are now easily accessible.

    You can also do GameObject.Find to find a GameObject rather than manually attaching another GameObject one by one, which works really well for a generic script used on many objects that uses a specific variable/function on a specific GameObject.

    Then you can also access the components of GameObjects as well, and if you access the script, you can call on a function or variable that THAT specific GameObject contains at that moment.

    There are a few different ways to do all of these, but just trying to introduce the concepts and not describe exactly how to do each. Some quick Google searches and Unity Script Reference searches should answer the majority of your general scripting questions.

    Well, that's my understanding of it so far for communicating between different objects/scripts, and this may have been a really quick overview over a really broad topic.
     
    Last edited: Jan 4, 2014