Intro to 3D Game Development

0 of 193 lessons complete (0%)

Scripting Part 2: Making Code Respond to Players

Send a Signal to the Chest Lid to Call the Start Animation Function

You don’t have access to this lesson
Please register or sign in to access the course content.

To send a signal from one script to another, we use a method called sendEvent. We’ll set up the code to use this, then handle an error in the next step.

  1. Create a new line after the one where you created the chestLid variable, still in the else part of your moveChest function.
  2. Call the .sendEvent() method on the chestLid.
  3. Give the method an argument (input) of the exact name of the function you made in your chestLidScript to start the opening animation. The easiest way to do this is to copy and paste it from chestLidScript, and then put “ ” double quotes around it.


This means you did the step correctly! The code won’t work right away, because it is possible that the chest lid doesn’t exist. We’ll fix this in the next step.