Moving cubes using events

Let’s move the cube to a different position using events. We will use a space bar to move our position to 5, 2, 0. First, we need to properly declare the event.

Then we need to create our space bar functionality. In it, we will pass in our position and then apply that position to our onTeleport event. Keep in mind, ever object that is listening to this event will always move to the same place.

Finally, we will create a function on our cube called Spawn and it will pass in the values from our onTeleport event.



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
Al Heck

Unity Developer and Software Engineer who loves making games with GameDevHQ