Scripting the player character's respawning 

In the previous section, we modified the CucumberManManager script to track how many lives remain and to destroy the UI image elements as appropriate. In this section, we will modify that script to accomplish the following when a life is lost:

  • Play the die animation
  • Respawn the player on a respawn pad

Let's start by modifying the CucumberManManager script:

  1. Add the following class variables:
     public Transform SpawnPad1;     public Transform SpawnPad2;     public Transform SpawnPad3;
  1. In the Hierarchy panel, select the CucumberMan GameObject and, in the Inspector panel, scroll until you locate the Cucumber Man Manager (Script) component.
  2. Drag SpawnPad1, SpawnPad2, and SpawnPad3 from the Hierarchy ...

Get Getting Started with Unity 2018 - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.