unity-atoms/docs/tutorials/mono-hooks.md
Miika Lönnqvist 532008c768
#189 Restructure tutorials and add two new tutorials (#190)
* Restructure tutorials and add two new tutorials

- Non-generated documentation review and edit
  - Consistent terminology
  - Stylistic changes
  - Minor structure changes
  - Minor clarifications
  - Typo fixes

- Split basic tutorial into two
- Tutorials are easier to follow when they are short and to the point
- Added event and variable instancer tutorials
- Had to bump node version for the docker container to work

* #189 - Fixing minor nitpicks

Co-authored-by: Adam Ramberg <adam@mambojambostudios.com>
2020-08-23 12:13:10 +02:00

1.3 KiB

id title hide_title sidebar_label
mono-hooks Mono Hooks true Mono Hooks

Mono Hooks

Mono Hooks save the effort of writing boilerplate code to raise Atoms Events from Unity's Event Functions.

A great use for Mono Hooks in our example would allow us to remove the Harmful.cs script created earlier. We could instead attach a OnTrigger2DHook.cs to the Harmful GameObject and toggle on Trigger On Enter like this:

mono-hooks-trigger-2d

We could then create a Collider2DAction called DecreasePlayersHealth.cs and add it to a Collider2D Listener attached to the Harmful GameObject:

    public class DecreasePlayersHealth : Collider2DAction
    {
        public override void Do(Collider2D collider)
        {
            if (collider.tag == "Player")
            {
                collider.GetComponent<PlayerHealth>().Health.Value -= 10;
            }
        }
    }

mono-hooks-listener

There is much less code written and the responses can be edited in the Editor.

That is it! We have covered the most fundamental pieces of Unity Atoms and a way to use them with Unity's built-in functionality. You can get far with these alone, but there are many more features in Unity Atoms and the subpackages to explore.