We’re introducing Meta accounts in August 2022: a new way to log into VR devices that doesn’t require a Facebook account. Learn more

RANDOM SPAWN POINTS

This next script is not necessary, but if you are up to it, will add an awesome element of fun. We are going to need three scripts to communicate. Our first script registers the spawnpoint with the spawnmanager, and the spawnmanager receives events from the spawnpoints and from the water balloon via the player who was hit.
In our first script, SpawnPointRegister, we simply have under When World is Started, Send event Register to a Control object variable, with parameter self. This is then attached to our spawn point, and references our SpawnController, which is a pyramid shape. Once the script is attached and references the controller, we can duplicate and place these spawn points all over our map.
The next script we need is SpawnManager, this starts by Receiving the Register event with parameter ObjectID. It then adds the ObjectID to the SpawnPoints variable, which is an object list.
Then, when Player Enters World, the script Listens to Events on the Player. Listen to is an awesome codeblock, allowing you to get all events that run on another object or in this case a Player. Please note, you cannot run a script on a player, but we can send events to the player, which will be received here.
Then, we will receive another custom event called PlayerHit, which is received with a PlayerID parameter. And then we will Respawn the PlayerID to a random item from the SpawnPoints list. You can find the Get Item at Index From List at the bottom of Operators. And then we will place in the Random Number codeblock, with zero on the left, and the Length of List codeblock on the right. Make sure to attach this script to the pyramid object. Wonderful! We can now respawn the player to a random location! Great work!
Last thing to do, on our WaterBalloon, under Collision With Player, placed below Score plus one. Place the Send Event to Object codeblock. Change MyEvent to PlayerHit, replace Self with the Player pill, and also place the Player pill in the empty parameter slot. Now on our SpawnManager, we will know what Player was hit, and can respawn them.
We can test this out, and splash that is so cool! And so much fun! In the next part we will create a way to reset the world.

Next Up