1 / 26

SE 320 – Introduction to Game Development

SE 320 – Introduction to Game Development. Lecture 8: Animations, GUIs, Debugging and IDEs Lecturer: Gazihan Alankuş. Please look at the last two slides for assignments (marked with TODO ). Topics Today. Animations Sources Scripting GUIs GUIText and GUITexture OnGUI magic

maddox
Download Presentation

SE 320 – Introduction to Game Development

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. SE 320 – Introduction to Game Development Lecture 8: Animations, GUIs, Debugging and IDEs Lecturer: GazihanAlankuş Please look at the last two slides for assignments (marked with TODO)

  2. Topics Today • Animations • Sources • Scripting • GUIs • GUIText and GUITexture • OnGUI magic • Debugging • Really debugging with breakpoints in MonoDevelop • Making the game pause before the next Update with Debug.Break() • Visual Studio and ReSharper

  3. Animations • Why do we need them? • Setting position/rotation in the Update() function can be limiting • Sometimes you want to visually design how things will move • What are they? • Some motion information in a component called Animation • Where do they come from? • Create visually in Unity • Unity Window->Animation • Create in modeling/animation tools • Blender, 3DS Max, Maya, etc. • How can we use them? • In code, you tell Unity which animation to start • The “activate trigger” script is an example

  4. Update() vs. Animations • In Update(), you can animate objects by setting their properties in code (location, rotation, scale, etc.) • Pros • Your calculations can be advanced (procedural animations, etc.) • Motions can depend on user input or other events in the game • Cons • For simple motions it can be too much work • E.g., a platform that does the same motion over and over • It can be difficult to adjust the motion so that it is • visually pleasing • exactly how you want it to be

  5. Update() vs. Animations • With animations, you can visually design how things will move • Pros • It’s easier to make things move how exactly you want them to • It’s easy to adjust speeds throughout the motion, implement curved motions and make motions visually pleasing • Cons • Static motions, cannot react to user input or other events in the game (blending, switching, mixing can help)

  6. Animations in Unity • You record the motion • You start playing that motion in game

  7. Animations in Unity • You record the motion • You start playing that motion in game

  8. Recording Animations in Unity • Window -> Animation opens the Animation pane • Add an animation component to the game object you want to animate (or let Unity do it for you while recording)

  9. The Animation Pane record, play, etc. curve for z (position in time) timeline (can drag with mouse) other objects in your scene keyframes (pinned values in time)

  10. Keyframe Animation • “I want the bus to be at this bus stop at 7:40, then I want it to be at this other bus stop at 7:45” • The bus driver does whatever is necessary to obey this. • You say “I want my cube to be here at time 0, I want it to be there at time 5, I want it to be there at time 8” • Unity calculates the motion that is necessary to make it happen

  11. Example

  12. How to Create a Keyframe Animation • Select the object you want to animate • Open the animation pane and press record (top-left corner) • Make your object how you want it at the beginning of the animation • Drag to a future time • Move/rotate/scale the object to how you want it at this time • Repeat 4-5 until you are done. • Any time, you can drag time or press play to review the current state of the animation

  13. Some Details • Pressing the record button • automatically adds an animation component if the object does not have one already • adds a new animation file if there was not one already in the animation component • You can have many animations for an object • In code you can play any of them, blend between them, etc. • Practice with the animation pane to find alternative ways of doing things (adding keyframes manually, dragging keyframes, etc.)

  14. Animations in Unity • You record the motion • You start playing that motion in game

  15. How to Play Animations • Automatically (easiest) • When “Play Automatically” ischecked, Unity will play the animation in the “Animation” property. • From code • animation.Play(“animationName"); • animation.CrossFade(“animationName2"); • Read the entry for the Animation class in the scripting reference • Can change speed, stop, mix, etc.

  16. Animations vs. Update() • Animations are static but easy, you tell them to play and they play for many frames • Changing position in every Update() call is messy • Is there anything in between? • Yes! Tweening. • GoKit: https://github.com/prime31/GoKithttp://forum.unity3d.com/threads/133823-Prime31-GoKit-Tween-Library-Live

  17. GoKit • Tell Unity to move an object to a certain point in four seconds, without having to do it in the Update() function • transform.positionTo(4f, new Vector3(10, 10, 10 )); • Many options to make it prettier. Look at the wiki • https://github.com/prime31/GoKit/wiki

  18. Topics Today • Animations • Sources • Scripting • GUIs • GUIText and GUITexture • OnGUI magic • Debugging • Really debugging with breakpoints in MonoDevelop • Making the game pause before the next Update with Debug.Break() • Visual Studio and ReSharper

  19. GUIs • Display scores, lives, etc. Any kind of textual or image-based output on the screen. • GUIText and GUITexture • Add them through Game Object -> Create Other. • Can be difficult to make them work otherwise. • Call their functions to do whatever you want to do with them • guiText.text = newScore + “ points”; //for example

  20. More Complex GUIs • OnGUI() function of MonoBehavior • This is not the kind of functions you are used to! • Unity does unusual things with it. You have to read the documentation carefully. • Calls it every frame but creates only in the beginning void OnGUI () { if (GUI.Button(new Rect (10,10,150,100), "I am a button")) { print ("You clicked the button!"); } }

  21. GUIs • You can use buttons for input (menus, etc.) • You can use text and images for output.

  22. Topics Today • Animations • Sources • Scripting • GUIs • GUIText and GUITexture • OnGUI magic • Debugging • Really debugging with breakpoints in MonoDevelop • Making the game pause before the next Update with Debug.Break() • Visual Studio and ReSharper

  23. Debugging • Debug.LogError • Debug.LogWarning • These let you display messages that won’t get lost in many others • Debug.DrawRay() • Debug.DrawLine() • These let you draw things in the scene view to see what exactly is going on in the game • Debug.Break() • This lets you make Unity pause itself after this frame

  24. Debugging with MonoDevelopwhile Coding in Visual Studio at the Same Time • Do this once after you created your Unity project • Edit->Preferences->External Tools is where you set the IDE that Unity will fire • Select Visual Studio • Double-click a script, this will create the Visual Studio project • Select MonoDevelop • Double-click a script, this will get the project in MonoDevelop’srecents • Select Visual Studio again • Close everyting • Do this at every run • Run MonoDevelop without running Unity • Select the project that is already in the recent projects • Run->Debug • This will run Unity • Set a breakpoint in MonoDevelop and see how it stops at that breakpoint • Run Visual Studio by either • running it from the start menu, • Or ensuring Edit->Preferences->External Tools is Visual Studio and double clicking on a script. • This does not affect MonoDevelop

  25. The BEST Development Environment for Unity Scripting that I Know of • Visual Studio + Resharper for coding • I asked for a classroom license. I also sent an e-mail. Still waiting. In the meantime go ahead and install the 30 day version. • MonoDevelop for occasional line-by-line debugging (explained towards end of presentation) • If you are using any other way, you would certainly develop a better game if you listen to me • (If you disagree, talk to me before discarding my advice… I have worked on large projects.)

  26. No Homework! • Good luck at the exam!

More Related