Scripting user interfaces
Before moving into our game, let's mention general UI programming in Unity. Each of the elements we have met in the previous section has a class that exposes some variables and some functions that we can use within our scripts. However, all of these classes are in a different namespace. As such, every time we want to use these classes, we need to add the following line of code at the beginning of our script:
using UnityEngine.UI;
Note
Actually, we can still use the classes without the using
statement by explicitly call the namespace every time. However, this approach is fine only if we need to use the namespace few times. Since we are programming with UI, it is good practice to import the namespace by adding the line of code shown previously.