1 / 19

Learning Unity

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.

fraley
Download Presentation

Learning Unity

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Learning Unity

  2. Getting Unity • http://unity3d.com/unity/download/ • http://www.microsoft.com/net/download

  3. Parts of the Unity Workspace • Scene – Place objects • Objects – View and select objects • Pre-Built – Code and object template • Variables – Modify existing objects

  4. 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

  5. Adding an Object • Here we add a cube • Properties • Location • Rotation • Scale • Change properties • Type in text • Use graphical interface

  6. The Camera or Viewpoint • Need to see scene from a given perspective • Can have multiple perspectives • Viewport not what user sees • See camera preview

  7. 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

  8. 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

  9. Collision • Add in a floor • New Cube object • Resize and move • Now when you run • Cube drops to floor

  10. Our Own Code • Create a Javascript asset • Can program in multiple languages in Unity • Name Script • Double click to edit

  11. 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)

  12. Our Own Code - Follow • Variable • vartoFollow : 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

  13. 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

  14. 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

  15. 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

  16. 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

  17. 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

  18. 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

  19. 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.

More Related