Graphics Reference
In-Depth Information
{
if (instance != null)
{
Debug.LogError ("Cannot have two instances of singleton.");
return;
}
instance = this;
}
public static MySingleton Instance
{
get
{
if (instance == null)
{
new MySingleton ();
}
return instance;
}
}
}
The singleton instance of our script may be accessed anywhere, by any script, simply
with the following syntax:
MySingleton.Instance.MySingletonMember;
1.1.4 Inheritance
Inheritance is a complex concept, which demands some explanation here because of its key
role within the scripts provided in this topic. Have a read through this section, but don't
worry if you don't pick up inheritance right away. Once we get to the programming, it will
most likely become clear.
The bottom line is that inheritance is used in programming to describe a method
of providing template scripts that may be overridden, or added to, by other scripts. As a
metaphor, imagine a car. All cars have four wheels and an engine. The types of wheels may
vary from car to car, as will the engine, so when we say “this is a car” and try to describe
how our car behaves, we may also describe the engine and wheels.
These relationships may be shown in a hierarchical order:
Car
-W heels
-Engine
Now try to picture this as a C# script:
Car class
Wheels function
Engine function
Search WWH ::




Custom Search