UI variable types

Each variable type is a class within the UnityEngine.UI namespace. Therefore, each of these variable types, in turn, have their own set of variables and functions that can be accessed. We'll discuss each variable type more thoroughly in the future sections and chapters, but, for now, let's just look at the standard template for accessing a property of a UI element in code.

In the Chapter4Text scene available in the provided project, you will see a UI Image named UI Variables Example. It does not have a sprite assigned to it and appears as a white square. The following script, AddSprite.cs, is attached to the UI Image:

using System.Collections;using System.Collections.Generic;using UnityEngine;using  UnityEngine.UI;public ...

Get Mastering UI Development with Unity now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.