Miscellaneous

Button

A UI Button is essentially a label with a button-like texture that can handle mouse events.

  • In the Hierarchy window, right click and add a UI > Button - TextMeshPro

    ../_images/button1.png
  • Use the Rect Tool to move/enlarge/shrink the button

  • In the Inspector window, you can select colors for specific events:

    ../_images/redbutton.png
  • In the Hierarchy, select the button

  • In the Inspector, find the On Click() Event section

../_images/_onclick.png
  • You need to link a GameObject and one of its internal function

    • This function will be called when the button is clicked

Variable qualifiers

class test
{

        [SerializeField] private float speed;    // show a private variable in the Inspector
        private const float maxspeed;                    // create const variable
        private static float nbinstances;               // class variable shared among instances, write test.nbinstances
        [range(0f,100f)] [SerializeField] float test;   // limit range values of the variable in the Inspector
}

Event Functions

FixedUpdate() { ... }  // called  at a regular pace, useful for applying forces independently of the framerate
Update(){...}
LateUpdate() { .. }  // called after the completion of all the update() calls, useful when scripting a follow camera

Awake() { ... }         // called immediately after instantiation, before any call of the start() function, useful to load resources
Start() { ... }     // called just before the first render on screen

Objects Pooling

Instead of instantiating and destroying lots of objects, it is more effective to create a pool of objects, activate them when needed, and deactivate them instead of destroying them.

For this, we need to:

  • Create a bunch of objects at the beginning

  • Set up a list of objects in the spawn manager