Download presentation
Presentation is loading. Please wait.
1
Quick Intro to Unity Lecture 2
2
My (totally-biased) Thoughts
Very clean organization More programmer-friendly (than Unreal) A good model for (parts of) our engine. Licensing is OK …but not for universities
3
interface Start it up! Hierarchy: a Scene Graph
Parent-child relationships Project: collection of assets Inspector: View / create components Edit component properties Scene / Game view: the current scene Warning: don’t do big things in game mode! Render mode Lighting mode
4
View manipulation Hand-tool selected (Q to enable, W to switch to move): Left-drag to pan Right-drag to rotate Any: ‘F’: Frame selected object (or double-click name) Right-click + WASD + QE Scroll-wheel to zoom Click on axes “cones” to switch to 2d view Click on central box to toggle perspective / ortho
5
Object manipulation [Add a 3d cube]
W, E, R toggle translate, rotate, scale Local / Global button Numeric values
6
Game object / component model
A very clean organization (imo) Add components to add functionality All game objects contain a Transform contains a parent-offset transform matrix internally contains pointers to parent / child g.o.’s Collider (Box, Capsule, Sphere, Mesh, etc.) ParticleEmitter Camera 3D Sound Sources … By adding components, you can call / listen for script methods / callbacks.
7
prefabs A GameObject “template”
Any instances of that prefab can: Modify a component value – that takes precedence Leave a component value alone: If the prefab changes, all of these values are updated. E.g. Make a “coin” prefab (collider, mesh, scale) Drag 100 instances onto scene. Each can have its own position If you modify the collider, all instances automatically change! Create by dragging from Hierarchy to Assets Make instances by dragging from assets to Scene Note the blue name in Hierarchy.
8
tags and layers Tags Layers A value (integer) attached to each object
[Show editing of Tags] e.g. Pickups, DeathTriggers, Player, etc. Very useful in scripts. Layers Similar idea, but more applied to Rendering e.g. Transparent layer, Water, Ignore-Raycast, etc.
9
Input System Axes and Actions [Show in Settings]
Configurable (remappable) Note the names e.g. “Horizontal” / “Vertical” axes e.g. “Jump” button Intentionally not a gamepad / key id or name. [Discuss benefits for game designers]
10
Scripting overview What’s it for? Basic process
Without: static objects that do nothing – boo! Determine what a game object does and when it does it. Examples: Handle collisions Start background music when level starts Update a gui when points are earned. … A taste of “real” programming. Basic process Create a new script asset (text file) Attach to one or more game objects Add / edit functionality to / in script Test in Unity Go back to step 3 until finished.
11
Scripting overview, cont.
[Create a C# script and edit] Documentation: Highlight item, then… Visual Studio: Ctrl + Alt + M, then Ctrl + H MonoDevelop: Ctrl + ‘ Example: Make a player object controlled by input axes Make a pickup prefab and trigger removal on hits. Naming convention e.g. Transform is the class, transform is this object’s instance. The classes sometimes have static-like variables / methods: e.g. Time.deltaTime; // an up-to-date float e.g. Quaternion.Slerp(Quaternion a, Quaternion b, float pcent);
12
scripting overview, cont.
A sampling of methods you can override (events) Start Update FixedUpdate [if we have a RigidBody component] OnCollisionEnter [if we have a Collider component] … public vs. private members Getting components: transform always exists (b/c all GameObjects have it) others you have to do this: e.g. Animator anim = GetComponent<Animator>();
13
Interacting with other G.OBJ’s
Option1: Make a public GameObject variable plus: level-designer can set it negative: fixed before run-time Option2: Find it by name / tag GameObject.Find or method GameObject.FindGameObjectsByTag or FindGameObjectByTag Can modify what you search for at run-time.
14
Mecanim overview A rigged / animated model has n clips
walk, run, idle, etc. Mecanim does the following: Blends between two animation clips Models a state-diagram You modify animation variables in code. The state diagram will transition to a new animation. Frees you from a lot of repetitive code. First step: Import a model with animation clips (optional) Under import settings, set the clip to loop
15
mecanim overview, cont. Step2: Open Animator (not Animation) window
Step3: Drag clips onto stage Step4: Create transitions between clips Step5: Tweak transition criteria / variables Step6: Set variables in script. [There’s much more you can do with Mecanim] Modify how the two clips are blended over time. Mask off parts of the skeleton …
16
GUI Overview A 2d overlay (HUD’s, minimaps, etc.) Composed of:
A canvas: Unity automatically creates one Buttons, Text-boxes, etc. The layout is pretty self-explanatory Unless you get into sprites…another topic! The 2D button (near the top) is very handy. These elements can (and often do) have scripts! NOTE: import UnityEngine.UI or you won’t see UI objects in script!
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.