

Because you added the script to the Openspot prefab all Openspots in your scene now also have the script attached. Select C Sharp as the Language and click Create and Add. In the Inspector, click Add Component, then choose New Script and name it PlaceMonster. In the Project Browser, select Openspot in the Prefabs folder. You’ll now create a script that can place a Monster on an Openspot. The prefab also contains an Audio Source component, which you’ll trigger to play a sound whenever the monster shoots a laser. To make placing easier, the project’s Prefab folder contains a Monster prefab.Īt this point, it consists of an empty game object with three different sprites and their shooting animations as their children.Įach sprite represents the monster at a different power level. When you’re done, your scene should look like this. Now use the Inspector to set the positions of these 12 Openspot objects to the following coordinates: Do this 11 times to make a total of 12 Openspot objects in the scene. Just drag and drop Openspot from the Prefabs folder in the Project Browser into the Scene view.

Now that you have a prefab, you can create as many copies as you need. Its name then turns blue in the Hierarchy to show that it’s connected to a prefab. While it’s tempting to repeat all those steps, Unity has a great solution for that: Prefabs!ĭrag and drop Openspot from the Hierarchy into the Prefabs folder in the Project Browser. Set the Audio Source’s AudioClip to tower_place, which you can find in the Audio folder, and deactivate Play On Awake. How cool is that?įollowing the same steps, add an Audio\Audio Source component to Openspot. Unity automatically detects the proper size for the collider.
