UFCEKU-20-3Web Games Programming Instantiating World Objects.

Slides:



Advertisements
Similar presentations
When is Orientated Programming NOT? Mike Fitzpatrick.
Advertisements

INNER WORKINGS OF UNITY 3D. WHAT WE ARE GOING TO COVER Intro to Unity Physics & Game Objects Cameras & Lighting Textures & Materials Quaternions and Rotation.
Unity Overview Using Unity 3.5 (Free version) [1]:
 2004 Prentice Hall, Inc. All rights reserved. Chapter 18 – Macromedia Flash MX 2004: Building an Interactive Game Outline 18.1 Introduction 18.2 Object-Oriented.
Advanced JS The World's Most Misunderstood Programming Language ) Douglas Crockford( Shimon Dahan
PACS – 10/19/131 Object-Oriented Programming “Object-oriented programming opens the door to cleaner designs, easier maintenance, and greater code reuseability.”
GameCamp! and Game Davis Introduction to Scripting in Unity®
HELLO WORLD: YOUR FIRST PROGRAM CHAPTER Topics  Hello World?  Creating a Unity Project –The Unity Project Folder  MonoDevelop: Unity's Code Editor.
Unity 3D game IDE 1.  Unity is a multi-platform, integrated IDE for scripting games, and working with 3D virtual worlds  Including:  Game engine ▪
Chapter 9 Introduction to ActionScript 3.0. Chapter 9 Lessons 1.Understand ActionScript Work with instances of movie clip symbols 3.Use code snippets.
Lua & Love2D Game Engine GALAGUH
UFCEKU-20-3Web Games Programming Unity 3D Physics Colliders and Object Collisions.
SE 350 – Programming Games Lecture 6: Programming with Unity Lecturer: Gazihan Alankuş Please look at the last slide for assignments (marked with TODO)
DEBUGGING CHAPTER Topics  Getting Started with Debugging  Types of Bugs –Compile-Time Bugs –Bugs Attaching Scripts –Runtime Errors  Stepping.
UFCEKU-20-3Web Games Programming Unity 3D Basic Concepts Using and Creating Prefabs.
EEC-693/793 Applied Computer Vision with Depth Cameras Lecture 13 Wenbing Zhao
Alice 2.0 Introductory Concepts and Techniques Project 1 Exploring Alice and Object-Oriented Programming.
SE 350 – Programming Games Lecture 7: Programming with Unity Lecturer: Gazihan Alankuş Please look at the last slide for assignments (marked with TODO)
Web Games Programming An Introduction to Unity 3D.
Web Games Programming Unity Scripting Fundamentals.
UFCFS D Technologies for the Web Unity 3D: Review of Topics and Related Concepts.
1 Chapter 12: Form Builder Objects and Flexible Code.
Learning Unity. Getting Unity
SE 320 – Introduction to Game Development Lecture 3: Unity’s Interface and Concepts Lecturer: Gazihan Alankuş Please look at the last two slides for assignments.
UFCFS D Technologies for the Web Unity Interface Features.
SE 320 – Introduction to Game Development Lecture 7: Programming Lecturer: Gazihan Alankuş Please look at the last two slides for assignments (marked with.
Games Development Game Architecture: Entities CO2301 Games Development 1 Week 22.
UFCEK-20-3Web Games Programming Unity 3D: Review of Topics Publishing for the Web.
1 Actionscript for Flash by Dr SC Li. 2 Understanding more about instances Symbolsgraphics buttons Movie clips Instances (without names) No interaction.
Problem Solving Methodology Rachel Gauci. Problem Solving Methodology Development Design Analysis Evaluation Solution requirements and constraints. Scope.
CLASSES CHAPTER Topics  Understanding Classes –The Anatomy of a Class  Class Inheritance –Superclasses and Subclasses –Virtual and Override 2.
GameDevClub CODE CHEAT SHEET NOTE: ALL OF THE CODE IS CASE-SENSITIVE AND THE SYNTAX IS STRICT SO A LOT OF YOUR ERRORS WILL PROBABLY COME FROM TYPOS If.
SE 350 – Programming Games Lecture 5: Programming with Unity Lecturer: Gazihan Alankuş Please look at the last slide for assignments (marked with TODO)
Basic Concepts of OOP.  Object-Oriented Programming (OOP) is a type of programming added to php5 that makes building complex, modular and reusable web.
UFCFX5-15-3Mobile Device Development Unity 3D Development for Android Unity Mobile Assets.
UFCFSU-30-13D Technologies for the Web An Introduction to Unity 3D.
Chapter 11 An introduction to object-oriented design.
Expressive Intelligence Studio // Center for Games and Playable Media // Unity Pro John Murray Expressive.
INTRO TO UNITY Building your first 3D game. DISCLAIMER  “This website is not affiliated with, maintained, endorsed or sponsored by Unity Technologies.
Yingcai Xiao Game Development with Unity3D Inside/Outside Unity3D.
Angry Teapots– using the physics engine in Unity Peter Passmore.
UFCEKU-20-3Web Games Programming Creating and Updating a Graphical Heads-Up Display (HUD)
Game Development with Unity3D
EEC-693/793 Applied Computer Vision with Depth Cameras
Quick Intro to Unity Lecture 2.
var variableName:datatype;
Game Development with Unity3D Inside/Outside Unity3D
First Person Shooter Project
3GB3 Game Design Unity 3D Basics.
EEC-693/793 Applied Computer Vision with Depth Cameras
Character Selection from a lobby in Unity
Game Development Unity3D.
EEC-693/793 Applied Computer Vision with Depth Cameras
Learning Java with Alice 3.0 Game Design Kathy Bierscheid
lecture 8 Our First Project
Applying Geometric Transformations
A beginner’s tutorial for Unity and VR
Week 6: Time and triggers!
lecture 9 Our First Project
Data Collections, Loops, Instantiation and some pieces that fell off.
Getting Started with Unity
Myo + Oculus Rift Tutorial
Fundaments of Game Design
Fundaments of Game Design
Fundaments of Game Design
EEC-693/793 Applied Computer Vision with Depth Cameras
Games Development Game Architecture: Entities
Unity Game Development
Unity Game Development
Presentation transcript:

UFCEKU-20-3Web Games Programming Instantiating World Objects

UFCEKU-20-3Web Games Programming Agenda Instantiating (spawning) Objects Dynamically During Runtime Steps Required to Prepare an Object for Instantiation Techniques to Assist in Positioning the Instantiated Object Dealing with Unwanted Objects

UFCEKU-20-3Web Games Programming Instantiating New Objects Instantiation is simply creating objects from a template during runtime – with Unity - a Prefab The term ‘instantiate’ comes from Object-Oriented Programming (OOP) terminology where a new instance of a class is said to be ‘instantiated’ It can also be used to duplicate world objects already in the scene Instantiating new objects while the application is running is also often referred to as ‘spawning’

UFCEKU-20-3Web Games Programming Preparing an Object for Instantiation Create the object to instantiate in the scene adding components as required Create a new Prefab in the project and drop the object created for instantiation onto the Prefab Delete the original object from the scene so it is only stored as a Prefab asset Create a script that uses the Instantiate() command together with a variable of type GameObject, attach it to an active world object Set the Prefab created as the object the Instantiate command creates by dropping it onto the GameObject variable in the Inspector Window

UFCEKU-20-3Web Games Programming Instantiate Command The Instantiate command has three parameters (arguments) Object to create, position to create it, rotation to give it: Instantiate(object,object’s position,object’s rotation);

UFCEKU-20-3Web Games Programming Instantiate Command Position and Rotation of objects to be instantiated must be specified as Vector3 values (X,Y,Z) used as follows: var aPrefab: GameObject;// variable of type GameObject Instantiate(aPrefab, Vector3(0,12,30), Vector3(0,0,90));

UFCEKU-20-3Web Games Programming Position and Rotation The position and rotation of objects to be instantiated can also be inherited from other objects via the inherited objects transform.position, and transform.rotation command This easiest method is to use a ‘dummy object’ positioned in the world where the instantiate object needs to be created. Then inherit the dummy object’s position and rotation values for the new instantiated object. The dummy object mesh renderer can be switched off so the dummy object is invisible in the scene

UFCEKU-20-3Web Games Programming Dummy Object Positioned in Scene at (0, 2, 5)

UFCEKU-20-3Web Games Programming Dummy Object Mesh Render Switched Off

UFCEKU-20-3Web Games Programming Instantiate.js attached to InstantiateCube // prefab name in project var ballInstance : GameObject; function Start () { // creates one ballInstance at the position of InstantiateCube Instantiate(ballInstance, transform.position, transform.rotation); }

UFCEKU-20-3Web Games Programming Removing Objects from the Scene Creating many clones of an object can adversely affect system performance Stray objects may also create unwanted collisions with other world objects Use the Destroy command to remove unwanted objects from the world The Destroy command is included in a script attached to the Prefab to be instantiated

UFCEKU-20-3Web Games Programming balltidy.js attached to ballInstance Prefab function Start () { /* Destroy has two arguments gameObject, and time in seconds before object is removed */ Destroy(gameObject,5); // destroys object after 5 seconds has elapsed }

UFCEKU-20-3Web Games Programming New Ball Prefab Created (Cube Visible)

UFCEKU-20-3Web Games Programming New Ball Prefab Created (Cube Hidden)

UFCEKU-20-3Web Games Programming Summary : Easy Instantiation Create the object to to be instantiate as a Prefab Attach a script with the Destroy() command to the Prefab Create and position a dummy object in the world Attach a script to the dummy object with the Instantiate() command and a GameObject variable Drag and drop the Prefab onto the dummy object script’s GameObject variable in the Inspector