Skip to content

Latest commit

 

History

History
273 lines (271 loc) · 26.8 KB

File metadata and controls

273 lines (271 loc) · 26.8 KB

Unity

Playable game for the source code in this repository

Getting started

  1. Create minimal playable game
  2. Basics
  3. Add polish to playable game
    • Removed camera follow component
    • Added slime enemy that uses new Enemy tag and updated WaypointFollower script to allow sprite flipping
    • Added OnPlayerDeath and OnLevelCompleted so PlayerMovement script can stop the player moving cleanly. Movement stopping is slightly different in each scenario
    • Renamed PlayerLife script to PlayerDamageController and added enemy killing by jumping
    • Added more functions to WaypointFollower script to allow clean destruction. This is handled by the death transition in the animator
    • Modified PlayerDamageController and PlayerMovement scripts to allow jumping off enemy head on kill
    • Modified PlayerMovement script jumping to allow variable jump height (https://forum.unity.com/threads/setting-variable-jump-height-for-the-second-jump.391842/)
    • Added dust effect to PlayerMovement script
    • Added Checkpoint script to handle checkpoints. CheckpointParent script used to make it easier to setup events. Event used to let player know last position. Be careful when copying the coordinates around, Vector3 is fine to copy because it's a struct but Transform will give you a reference (see https://learn.microsoft.com/en-us/dotnet/standard/design-guidelines/choosing-between-class-and-struct)
    • Created 1-way platforms by adding another layer and ticking Use One Way in the Platform Effector 2D component
    • ItemCollector script now fires an event when an item is collected. Created new FinishGated script and moved counting logic there. Moved collected item count from canvas into game world above finish flag. These work together to show the user they need to collect all the items to finish
    • Added Fader script to fade and unfade finish flag to give an extra visual indicator that items need to be collected to unlock the flag. Also created FaderVS to show how visual scripting can be used in conjunction with C# scripts. They are both reasonably similar and are used in the FinishGated script
    • Replaced old input system with new input system
    • See Building links above for final build (this was more fiddly than expected due to the default WebGL template not having sensible defaults)
  4. Optional

Notes

  • Glossary
    • Component - contain properties which you can edit to define the behavior of a GameObject
    • GameObject - fundamental objects in Unity that represent characters, props and scenery
    • Prefabs - templates for GameObjects with preset components - basically drag a GameObject that's been setup to a folder, usually Prefabs
  • Fundamentals
    • All game objects have a Transform component because they're displayed on the scene somewhere
  • Keyboard shortcuts
    • QWERTY - these map to the editor common tool group that starts with the Hand
    • SHIFT+F - Zoom into currently selected game object. Or double click on the game object
    • CTRL+D - Duplicate the currently selected game object
    • CTRL+P - Play / Stop playing game
    • TileMaps
      • Hold Shift and left-click to erase a tile you just layed
      • Rotate a tile before painting by using [ and ]
    • Hold CTRL when moving a sprite to move in increments
    • Hold ALT when using Rect Tool on a sprite to resize from the centre
  • Areas
    • These are in alphabetical order for easy reference
    • Animations
      • Don't forget to check Loop Time in the inspector for the animation clip (asset with triangle icon) to make sure the animation loops
      • You can drag sprites into the animation timeline but it's a bit fiddly because sometimes it won't let you. Just make sure to select the game object and it should work
      • Usually need to change transition defaults so Has Exit Time is unchecked and Transition Duration is 0
      • Triggers are one-off events that can be used in the Animator (e.g. death)
      • Animation window
        • Dots in top right allow you to Show Sample Rate which will let you change the speed of the animation
      • Recording animations is easier than trying to do things programatically
    • Audio
      • Play On Awake is checked by default which usually isn't what you want
    • Designing
      • Using Squares as initial game objects mean you get a Sprite Renderer component added automatically, making setup slightly faster
      • Whenever you nest a game object under another game object, the Transform component becomes relative to the parent (e.g. if you put the camera under the player object, the camera will follow the player)
      • Freeze rotation Z on rigid body to stop it rotating about that plane
    • Editor
      • If you mess up Editor layout, can just select Default in the top right
      • Prefabs are highlighted in blue. Edit Prefabs by clicking on the > arrow on right (if you edit the game object directly it only applies to that one and not all the others)
      • When adding a new game object, check the Z value because it sometimes isn't exactly 0
      • Hierarchy window
        • Eye icon to left of objects lets you toggle visibility
    • IDE (e.g. Visual Studio)
      • Moving scripts around after creating them can break the intellisense so need to regenerate using Edit -> Preferences -> External Tools -> Select your IDE in External Script Editor -> Click Regenerate project files. This seems to happen more often with Visual Studio Code
    • Inspector
      • ? icon takes you straight to documentation
    • Project Settings
      • Input Manager lets you rebind keys for old input system
    • Sprites
      • Click the sprite group (not the individual frames) to set the Pixels Per Unit value before working with a sprite
  • Troubleshooting
    • When changing UnityEvents, you need to setup up the serializable fields for events again otherwise you'll get strange type errors
    • Visual Studio Code
      • When adding new scripts, intellisense may not work for the new files. This can be fixed by regenerating the project files as per the setup steps
      • In some cases regenerating will not fix the issue, seem to be quite a few bugs here
      • Overall, the Visual Studio integration seems a lot more bug free, so recommend using that instead