This article is Part 15 in a 25-Part Series.

This will be a short post as it is more about the animation than anything else. You will need an electricity aura sprite like the below for effects.

I will show another way of doing animation - by manipulating its transform.

Start by dragging your PlayerTank prefab to the hierarchy. Then add your Electricity Sprite as a child to the PlayerTank and EnemyTank. Call it Electricity. Reset its transform.

You might need to adjust its scale to fit it to surround your tank.

. Also set its Order in Layer to 2 so that it sits on top of all the rendered objects.

Then disable the Electricity Game Object.

Now let’s do animation for the Electricity. Go to your Project Window, create an Animation Controller and rename it as PlayerTank. Select your PlayerTank and add an Animator Component (Miscellaneous -> Animator). From the Animator Component, set the Controller to point to the PlayerTank Animator Controller you created earlier.

Open the Animation Window via the Unity Editor Menu(Window -> Animation). Click on “Create” at the Animation Window. Unity will prompt for a name for the animation, call it TankCreating. Now you should be able to Add Property from the Animation Window.

  • Add 2 properties (Electricity->Is Active) and (Electricity->Transform->Rotation) from the Animation Window.

Once added, you should be able to see something like the below.

  • Now click on the red circle(symbolizing record). If it is depressed, means we are in recording mode. Check the box for Electricity: Game Object.Is Active.

  • Click on the timeline at point 0:15, you should have a white line that will move to that position. Once the white line is at point 0:15, Set value of Rotation.z to 90and ensure Electricity: Game Object. Is Active is still checked.

  • Do the same for the above at timeline 1.15.

  • Now Click on the timeline at point 0:30, that white line should move to that position together. Once the white line is at point 0:30, set value of Rotation.z to 180 and ensure Electricity: Game Object. Is Active is still checked.

  • Do the same for the above at timeline 1.30.

  • Now Click on the timeline at point 0:45, that white line should move to that position together. Once the white line is at point 0:45, set value of Rotation.z to 270 and ensure Electricity: Game Object. Is Active is still checked. Do the same at timeline 1.45.

  • Now Click on the timeline at point 1:00, that white line should move to that position together. Once the white line is at point 1:00, set value of Rotation.z to 0 and ensure Electricity: Game Object. Is Active is still checked.
  • Do the same at timeline 2.00. But uncheck Electricity: Game Object. is Active Click on the Add Event button as indicated with the Mouse Pointer below.

  • A white ribbon(turns blue when selected) will appear just below the 2:00 timeline. And the inspector should come up with the title “Animation Event”. Select from the drop-down SetHealth().

  • Now Click on the timeline at point 0:00, that white line should move to that position together. Once the white line is at point 0:00, click on the Add Event button as indicated with the Mouse Pointer below. A white ribbon(turns blue when selected) will appear just below the 0:00 timeline. And the inspector should come up with the title “Animation Event”. Select from the drop-down SetInvincible().

  • Click on the red circle symbolizing record to stop recording. Now your Electric Aura is completed. Click on Play of the Animation to start enjoying the feeling of invincibility.

The next step is to set the TankCreating Animation as the default state as this will be the first animation that will play when the tank first appears on the Scene. Then we need to do is from the Animator add another state for the animation to transit to after electricity aura exipres. Open up the Animator Window from Unity(Window -> Animator). Select the Tank animator from your Project Window.

Right Click on the Animator Window Base Layer and select Create State -> Empty. Rename the New State as Normal. Your Base Layer should look like the below.

Right click on the TankCreating box and select Make Transition. Drag the arrow to the Normal box. Select the arrow created and ensure the Inspector shows Has Exit Time checked

No new code required

That’s all for the electricity aura effect animation. Remember to save your PlayerTank Prefab. Next post we will talk about the explosion animation when a tank is destroyed.

This article is Part 15 in a 25-Part Series.

s