CARROTREVOLT LABS
INTERACTIVE STUDIES / 05

Code Lab 02 C#

All labsObjects · towards Unity
LEVEL 1 · SEQUENCE1 / 15

First block

    Program.cs
    0 INSTRUCTIONS

    Console

    Ready

    Scene

    DRONE (0, 0)

    Memory

    VARIABLES IN SCOPE

    Execution

    STEP 0
      CODE LAB 02 · C#

      Objects you can see.

      Classes, objects and references, the way Unity scripts are built. The Memory panel now shows the heap: every object made with new.

      1. Variables of a class hold an arrow (→ #3) to an object in the heap. Two variables can point to the same object; null points to nothing.
      2. Structs like Vector3 are stored inside the variable and copied when assigned.
      3. Faded objects in the heap have no arrow pointing to them any more: C# will clean them up (garbage collection).
      4. Scene.Add puts a MonoBehaviour in the scene. Then the lab calls Start() once and Update() every frame (20 per second), and draws each object at its transform.position, with a dot for every frame.
      5. Step Into (F11) goes inside methods and constructors; Step (F10) runs them in one go.

      Classes go at the end of the file, after the main program, as C# requires. Progress and code are saved in this browser.