Presentation is loading. Please wait.

Presentation is loading. Please wait.

UFCEKU-20-3Web Games Programming Unity 3D Basic Concepts Using and Creating Prefabs.

Similar presentations


Presentation on theme: "UFCEKU-20-3Web Games Programming Unity 3D Basic Concepts Using and Creating Prefabs."— Presentation transcript:

1 UFCEKU-20-3Web Games Programming Unity 3D Basic Concepts Using and Creating Prefabs

2 UFCEKU-20-3Web Games Programming Agenda Role of a Prefab Creating a Prefab Using a Prefab as a World Object Instance Modifying Prefabs to Affect World Objects.

3 UFCEKU-20-3Web Games Programming Role of Prefabs A prefab is a prefabricated object made of pre-selected components e.g. meshes, textures, physics, scripts etc. Prefabs exist in the Project Window and when dragged and dropped into the world becomes a world object A world object based on a prefab will ‘inherit’ all the properties and behaviours of the prefabricated object on which it is based. When a prefab is modified in the Project Window all world objects based on the prefab will be updated with the new modifications. Some or all of the changes can be ‘overidden ’

4 UFCEKU-20-3Web Games Programming Camera Mesh Audio Listener The First Person Controller is a prefabricated object FPS.js Code to handle FPS Walker etc. Mesh collider Scripts

5 UFCEKU-20-3Web Games Programming Creating Prefabs In order to create a Prefab, simply drag a object that you've created in the scene into the Project View. The object's name will turn blue to show that it is a Prefab, then rename your new Prefab The object and all its ‘children’ have been copied into the Prefab data The Prefab can now be re-used in multiple instances The original object in the Hierarchy has now become an ‘instance’ of the new Prefab.

6 UFCEKU-20-3Web Games Programming Example of a Complex Prefab (Lerptz)

7 UFCEKU-20-3Web Games Programming Prefab Instance and Inheritance Drag the Prefab from the Project View into the Scene or Hierarchy View This instance is linked to the Prefab If you have selected a Prefab instance, and want to make a change that affects all instances, you can click the Select button in the Inspector to select the source Prefab Inheritance means that whenever the source Prefab changes, those changes are applied to all linked Objects, e.g. adding a new behavior script to a Prefab will affect all linked objects.

8 UFCEKU-20-3Web Games Programming Modifying a Single Prefab Instance It is possible to change the properties of a single instance while still retaining the link to the Prefab Change any property of a prefab instance in the Inspector Window, and watch as the variable name becomes bold,the variable is now overridden All overridden properties in the instance will not be affected by changes in the source Prefab. This allows you to modify Prefab instances to make them unique from their source Prefabs without breaking the Prefab link.

9 UFCEKU-20-3Web Games Programming Creating a Simple Prefab (Cube) Cube Cube.js Code to handle message sent by other scripts attached to other objects Prefab created from a cube with a material added and attaching a script.

10 UFCEKU-20-3Web Games Programming Summary Unity’s Prefab facility allows developers to customize an object’s properties and behaviors inside the 3D environment. Once the object is developed as required it can then act as a prefabricated object for instances (clones) of the object in the environment. If required, properties or behaviors of a particular instance can be overridden without losing the link to the original Prefab. Thus some instances can have specialized properties and behaviors that suit their particular role in the scenario.


Download ppt "UFCEKU-20-3Web Games Programming Unity 3D Basic Concepts Using and Creating Prefabs."

Similar presentations


Ads by Google