Samples
To import samples, use the Package Manager window:
- Go to
Window > Package Manager
and, in the packages list view, select Global Message. - In the package details view, find the Samples section.
- Find the sample you want to import and click the Import button next to it. Unity imports the samples into
Assets/Samples/Global Message/<package version>/<sample name>
.
Overview 101
This sample is intended as a practical addition to the documentation as it shows off most topics in one scene. However, it is not meant as a guide on how to correctly structure your game using GlobalMessage.
The scene is located inside the samples folder under Overview 101/Scenes/Overview 101
.
Play the Sample
Enter Play Mode to interact with the scene:
- Spawn different colored balls using the buttons.
- Make all balls of one color jump using the buttons.
- Delete balls by clicking on them.
- Clicked balls count is visible in UI.
- Balls that fell off the edge are counted in the UI.
Understand the Sample
Investigate the scene hierarchy to find the following use cases:
- Sending via component without parameter: Spawn Blue ui button (child of Canvas)
- Sending via component with parameter: Spawn (Multiple) Pinks ui buttons (children of Canvas)
- Sending from code via obj field:
ClickedBallLogic
component on theBall Base Prefab
in thePrefabs
folder. - Sending from code only: Fallen Ball Counter
- Receiving via component with and without param: Simple/Generic Spawner (children of Ball Spawners)
- Receiving in code via obj field:
Jump
component on ball prefabs in thePrefabs
folder. - Receiving in code only: Fallen Ball Counter showing off Send from Editor
Test sending a Message directly from the Editor:
- Enter Play Mode.
- Open the Overview Window (
Windows > Global Message
). - Double-click the
SpawnGenericMsg
Message to open its Info Window. - Drag a prefab into its
Spawned Prefab
field. You could use theBall Blue
prefab from thePrefabs
folder. - Adjust the
Spawn Count
field to spawn multiple prefabs at once. - Click the
Send from Editor
button to directly send theSpawnGenericMsg
Message with your selected parameters from the Editor (this can be very helpful for testing).