Skip to content

Less than half-finished. Messing around with Unity 2D tutorial.

License

Notifications You must be signed in to change notification settings

idbrii/game-ofclones

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

52 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

About

This project refactors the "Unity Projects: 2D Platformer" from Unity Asset Store to reduce code duplication and engineer it to follow the component entity pattern. This pattern is essentially the same concept that Unity exposes: you have a GameObject (your entity) and can add scripts (Components) to it. We can abstract out common behaviors into a common class: Instead of PlayerHealth and Enemy containing its own health, we have a Vitality component that handles both cases.

One exception is that Unity provides Components with an Update function instead of having a corresponding System that updates its components. You could still write a System using FindObjectsOfType(typeof(Vitality)), but the documentation warns "this function is very slow". Alternatively, you could have Components register/deregister themselves with the System on in Start/OnDestroy. Neither of these methods seem to follow the core intent of Unity's design and have not been implemented.

Read more about Component Entity System

Other changes

I've also made some minor style changes:

  • Use ToolTips instead of comments on public variables.
  • These show up in the inspector to make them useful without diving into the code.
  • Use CompareTag instead of string comparison.
  • I think the function call is as readable as string comparison and it's supposed to be better for performance.
  • Four spaces for indent.
  • No space after method names.

About

Less than half-finished. Messing around with Unity 2D tutorial.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages