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.
Animation-based attack trigger - Unity Tutorial
From the course: Unity 5: 2D Level Design
Animation-based attack trigger
- [Instructor] Now that we've connected up the AlienB attack animation, let's go ahead and finish off the logic we need to make this work. Let's select the AlienB game object from the Hierarchy window, then we'll change the Order in Layer to 2, so that it sits above the Sprites in our tile map. Next, let's go ahead and save this as a Prefab. We'll drag it into our assets, JetroidLevelDesign Prefab folder. Now, we're going to modify our alien to attack the player, but only halfway through the attack animation. To get started, let's open up the AlienB attack script. Let's create a new flag to see if we're ready to attack the player. We'll make this a private boolean, and we'll call this readyToAttack. Next, we're going to modify the OnTriggerEnter2D. The first thing we want to do after we test that the game object tag is set to "Player" is see if we're ready to attack. If this is set to true, we're going to want to kill the player. If not, we're going to trigger the attack animation. So…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.