From the course: Unity 5: 2D Level Design

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Use the switch

Use the switch - Unity Tutorial

From the course: Unity 5: 2D Level Design

Start my 1-month free trial

Use the switch

- [Instructor] Now that our switch works, let's go ahead and add the logic we need to connect the switch to the door. This way when the player walks over the switch, they'll be able to open the door automatically. Let's start by opening our DoorTrigger script. Inside of here, we're going to need to create a new public method with a return type of void and we're going to call this Toggle. Here, we'll pass in a boolean called value that we can use to determine whether we want to toggle the door open or closed. We'll test to see if the value is true and we'll also test for false. If it's true, we'll call door.Open. And if it's false, we'll call door.Close. Next, we're going to want to wire up the switch to be able to call the door's trigger toggle method. Let's go into our Switch script and we're going to add an array of door triggers. At the top of our class, let's create a public DoorTrigger array and we're going to call this doorTriggers. One of the reasons we're going to use an array…

Contents