learning unity
DESCRIPTION
Learning Unity. Getting Unity. http://unity3d.com/unity/download / http://www.microsoft.com/net/download. Parts of the Unity Workspace. Scene – Place objects Objects – View and select objects Pre-Built – Code and object template Variables – Modify existing objects. - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: Learning Unity](https://reader035.vdocuments.site/reader035/viewer/2022062305/5681627b550346895dd2e8c8/html5/thumbnails/1.jpg)
Learning Unity
![Page 2: Learning Unity](https://reader035.vdocuments.site/reader035/viewer/2022062305/5681627b550346895dd2e8c8/html5/thumbnails/2.jpg)
Getting Unity
• http://unity3d.com/unity/download/
• http://www.microsoft.com/net/download
![Page 3: Learning Unity](https://reader035.vdocuments.site/reader035/viewer/2022062305/5681627b550346895dd2e8c8/html5/thumbnails/3.jpg)
Parts of the Unity Workspace
• Scene – Place objects
• Objects – View and select objects
• Pre-Built – Code and object template
• Variables – Modify existing objects
![Page 4: Learning Unity](https://reader035.vdocuments.site/reader035/viewer/2022062305/5681627b550346895dd2e8c8/html5/thumbnails/4.jpg)
Object Oriented Programming
• Each object represents a thing or a collection of ideas
• Ex “Car”– Functions: (things to do) accelerator, turn, stop– Variables: (Features) color, speed, location– Skin: (Visual appearance) polygons in space• Relevant in Unity
![Page 5: Learning Unity](https://reader035.vdocuments.site/reader035/viewer/2022062305/5681627b550346895dd2e8c8/html5/thumbnails/5.jpg)
Adding an Object
• Here we add a cube• Properties– Location– Rotation– Scale
• Change properties– Type in text– Use graphical interface
![Page 6: Learning Unity](https://reader035.vdocuments.site/reader035/viewer/2022062305/5681627b550346895dd2e8c8/html5/thumbnails/6.jpg)
The Camera or Viewpoint
• Need to see scene from a given perspective
• Can have multiple perspectives– Viewport not what user sees– See camera preview
![Page 7: Learning Unity](https://reader035.vdocuments.site/reader035/viewer/2022062305/5681627b550346895dd2e8c8/html5/thumbnails/7.jpg)
Running the program
• Click on the “play” arrow
• Click again to stop• See from the viewpoint
of the camera• Everything is dark,
need some lights– Add directional light
![Page 8: Learning Unity](https://reader035.vdocuments.site/reader035/viewer/2022062305/5681627b550346895dd2e8c8/html5/thumbnails/8.jpg)
Adding Code
• To make it do anything, need to add code
• Select pre-built code – Rigidbody– This provides physics– Now object drops
• Note: drag the “game” tab to view scene and game view at the same time
![Page 9: Learning Unity](https://reader035.vdocuments.site/reader035/viewer/2022062305/5681627b550346895dd2e8c8/html5/thumbnails/9.jpg)
Collision
• Add in a floor– New Cube object– Resize and move
• Now when you run– Cube drops to floor
![Page 10: Learning Unity](https://reader035.vdocuments.site/reader035/viewer/2022062305/5681627b550346895dd2e8c8/html5/thumbnails/10.jpg)
Our Own Code
• Create a Javascript asset– Can program in multiple
languages in Unity• Name Script• Double click to edit
![Page 11: Learning Unity](https://reader035.vdocuments.site/reader035/viewer/2022062305/5681627b550346895dd2e8c8/html5/thumbnails/11.jpg)
Our Own Code - 2• Code editor• Code starts with some basic things• Ignore “#pragma strict”• function Start() {}
– Runs when you hit the start button• function Update() {}
– Runs every time things change• Automatic tick (moves objects,
updates physics, updates graphics, calls Update functions etc)
![Page 12: Learning Unity](https://reader035.vdocuments.site/reader035/viewer/2022062305/5681627b550346895dd2e8c8/html5/thumbnails/12.jpg)
Our Own Code - Follow
• Variable– var toFollow : Transform;– A variable is a space to hold
a value that might change• Update– this.transform.position =
toFollow.position;– Move this object to the
follow object
![Page 13: Learning Unity](https://reader035.vdocuments.site/reader035/viewer/2022062305/5681627b550346895dd2e8c8/html5/thumbnails/13.jpg)
Adding Our Code
• We want the camera to follow the cube
• Simple click and drag code to the camera
• But what about the variable? We need to tell it what to follow
• So drag the cube to the ToFollow variable
![Page 14: Learning Unity](https://reader035.vdocuments.site/reader035/viewer/2022062305/5681627b550346895dd2e8c8/html5/thumbnails/14.jpg)
Adding Our Code - 2
• Now when you run, the camera moves with the falling cube– Unfortunately you can’t see the
cube because you are inside of it!
– To fix, we could change the position code (to move it away)• But instead we will learn about
nesting
![Page 15: Learning Unity](https://reader035.vdocuments.site/reader035/viewer/2022062305/5681627b550346895dd2e8c8/html5/thumbnails/15.jpg)
Nesting
• Right click on the script and select remove script
• Now drag the Main Camera onto the cube in the far left bottom window– This means that the camera
will move relative to the box– In this way, you can embed
multiple layers
![Page 16: Learning Unity](https://reader035.vdocuments.site/reader035/viewer/2022062305/5681627b550346895dd2e8c8/html5/thumbnails/16.jpg)
Adding Assets• You can import assets which are
collections of code and objects created by other people
• Import the character controller and confirm the import
• The assets will appear in the bottom center window
• Note – I have deleted the main cube– In the hierarchy, drag the camera
off, then select the cube and hit the delete key
![Page 17: Learning Unity](https://reader035.vdocuments.site/reader035/viewer/2022062305/5681627b550346895dd2e8c8/html5/thumbnails/17.jpg)
Prefab• Assets can contain images,
code, polygons, music, etc.• They can also contain Prefabs
– Prefabs are collections of objects and scripts to place in the world
• Select and drag the first person controller onto the screen
• In play mode, you can now move around (asdf, or arrow keys), space to jump, and look with the mouse
![Page 18: Learning Unity](https://reader035.vdocuments.site/reader035/viewer/2022062305/5681627b550346895dd2e8c8/html5/thumbnails/18.jpg)
Back to Programming - Conditionals
• Create new script called FallOff• If you fall off of the world, this
will put you back at the beginning
• Conditional “if”, only run the code if true
• If the y coordinate is below a given level, then move to 0,0,0
• Then attach to your character– Experiment with running off
of the platform
![Page 19: Learning Unity](https://reader035.vdocuments.site/reader035/viewer/2022062305/5681627b550346895dd2e8c8/html5/thumbnails/19.jpg)
A Simple Game
• Just by adding in a few platforms, we can make a game.
• Try to get from the left platform to the right one.