Game Development Reference
In-Depth Information
Illustration 31: Creating a new prefab from an object
I believe it is a good time to dive again in programming details, and this time in some details
of object- oriented programming. One of the important features of object orientation is the
ability to reuse the code, and this is usually achieved by using inheritance. In Unity, however,
there is a different technique that can be used, namely composition over inheritance . In this
technique, we separate the different behaviors objects can expose into separate scripts. After
that we can arbitrarily attach these scripts in any combination to the objects. For example, we
can have a static target that does not move by attaching Target script only to it. If we want this
target to move as well, all we have to do is to attach AutoMover script to it. Similarly, an object
that has AutoMover script but does not have Target , is actually a moving object that cannot be
shot and hit.
Search WWH ::




Custom Search