Unity Respawn using Delegates and Events

Here’s a quick way to respawn in Unity using delegates and events…

In this example, we’re going to use the SpaceBar to initiate the respawn event:

Inside our Main script (attached to the MainCamera), we’ll create the Teleport delegate and give it a Vector 3 value that will be the destination. And also create an event that is tied to the delegate, and make a variable to hold our destination as a Vector 3 value:

Add the space bar as the trigger:

Inside the Cube script (attached to the cubes) we’ll add the Respawn method and attach it to the onTeleport event:

Now the Respawn method will be invoked from the Teleport delegate when the onTeleport event is triggered from the space bar.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Richard Morgan

Richard Morgan

Unity and Flutter developer interested in creating mixed-reality applications.