Collecting objects to heal or damage
In this tutorial we will show you how to collect a coin to heal or damage the player.
Press 'L' to bring up the library and place and asset you want the player to collect. In this example we used a coin.
Add 'Collectable' component
Click 'Edit Logic' button on the right to bring up the extra settings.
Set 'Collect Message' to anything you like. In this example we used 'coin'
Now when the player runs into the coin it will collect it and send a message 'coin' out into the world. We need to now make something to receive this message and give the action we need. The 'Damage' or 'Healing'.
Add another copy of the coin and make it 'invisible' and give it a name that we can use to make it easy to look up. In this example we called this one 'Acoin invis' and the other coin 'Acoin'
Give the invisible coin the 'No collisions'
Add the 'Message Broadcaster' Behaviour and set Visible to False.
'Message to Send' - Here is where you tell the collection to be Damage or Heal. Damage:10 or Heal:10 - case sensitive and no spaces. You can change the number as you need.
Set 'Wait Before Broadcast' to True
Set Message Required to 'coin' or whatever you used on the original coin.
Set Broadcast Only Once to True and its Delay to 1
Last thing we need to do is parent the invisible coin to the collectable coin. When the coin is collected it disappears and also taking the message broadcaster with it.
Click the 'Hierarchy' button in the bottom left corner.
Search for the name we used earlier. 'Acoin' will bring up both.
Parent the invisible coin to the collectable coin by clicking on the target symbol and dragging to the Acoin name plate.
Done! now you have a collectable coin that Damage or Heals the player.
Last updated