**Unity Platformer Microgame**
What is it? ==== 1. Fully functional single level game 2. Example of techniques 3. Basis for several online tutorials Setting up ==== 1. Unity version 2022.3.43 (hasn't been updated!) 1. New Project 2. All Templates 3. 2D Platformer Microgame 4. Download template 5. Create Project 2. Can then update to newer yourself 1. In Hub: change editor version 2. Launch 3. Allow to convert 4. Save Tour ==== 1. Sprites 1. Look in Character > Sprites, e.g. PlayerRun 2. Click "Open" to open sprite image file 3. Open in Sprite Editor * Slice options: auto or grid 4. Open sprite asset and use arrows to move through frames 5. Select player in scene, open Window > Animation and preview animations 4. Character > Animations 1. Player and Enemy transition graphs 2. Click on transition lines & look at conditions 5. Environment > Tiles / Sprites 2. Prefabs 1. Blue in scene 2. Especially Enemy, anything changed affects all enemies 3. UI Canvas includes complex structure & layout 3. Tilemap editor 1. Look at Grid & sub-objects 2. Select Foreground, Level, Background, Far Background & turn on and off 3. Note that only Level has a Tilemap Collider component 4. Window > Package Manager; Packages: Unity Registry; 2D or search for Tilemap 5. Window > 2D > Tile Palette 6. Select level 7. Choose brush; pick a tile/tiles in tilemap; paint in level 4. Scripts 1. Timed events 1. Death Zone (Scripts > Mechanics > DeathZone.cs) 1. Select zone & click "Edit Collider" to look at death zones 2. When something enters 1. See if it has a PlayerController (= see if it's the player) 2. Schedule immediate PlayerEnteredDeathZone 3. PlayerEnteredDeathZone schedules immediate PlayerDeath 4. PlayerDeath turns off camera, control, plays sound, plays anim, schedules PlayerSpawn in 2 seconds 5. PlayerSpawn teleports to spawn point, resets camera, health, etc., schedules EnablePlayerInput in 2 more seconds 6. EnablePlayerInput turns input back on 2. Implementation in Scripts/Core/Simulation.Event.cs, Simulation.cs, HeapQueue.cs 1. Simulation.Event 1. Class with tick (when to run) and Execute() 2. Not used in this game, but Predicate in case conditions change before Execute 2. Simulation 1. Uses HeapQueue = generic heap 2. Schedule sets a time as now+delay, adds to heap 3. Tick 1. If top event should already have happened, execute it 2. Loop until no events or only future events left 3. Could do with time stamps in entities, where each checks its own. * See Mechanics > PatrolPath.Mover.cs 2. GameController 1. Global object containing game state * Has code to enforce singleton, though could avoid 2. Ticks Simulation object 3. Has a PlatformerObject (Camera, Player, Spawn Point, control params) 4. Token Controller 1. Find all tokens (on Awake, not every frame!) 2. Tick token animation 5. MetaGameController 1. UI Canvas for menus (manually enable to show) 2. Handles showing & hiding menu screens 6. Audio source (background audio) 3. Main Camera * Uses Cinemachine: camera is CM vcam1, set to follow Player 4. Player Controller 1. Control & state for player (notice public vs. private) 2. Expensive GetComponent on awake & save 3. Update 1. Button down: check if OK and prepare to jump (look at UpdateJumpState) 2. Look at ComputeVelocity (override from parent) 3. Button up (in Update): *schedule* PlayerStopJump now (boring, but can extend) 4. Sets animator state to trigger sprite changes (look for "grounded") 5. EnemyController 1. Collision, check for player, schedule immediate PlayerEnemyCollision * PlayerEnemyCollision checks who is higher (vertically), damage or death to enemy or player 2. Update: move on path 1. Patrol path has start and end points 2. PatrolPath.Mover gives position bouncing back and forth between start & end 3. Enemy just uses x position of Mover 3. Custom patrol path editor Editor > PatrolPathEditor.cs 1. Be sure to enable Gizmos to view & edit 2. Gets start & end position, zero's out (relative) y 3. Draws as two yellow discs with dotted line in between 6. Tokens: pretty similar to enemies (but w/o mover) * Note that TokenController finds & tracks all the tokens in the scene.