Time for action – creating the black bird
As with the two birds discussed earlier, inheriting from the red bird makes the black bird's creation much easier:
- As with the others, this bird is initially created in the same way as the red bird, readjusting the Radius for its increased size.
- Again, we create a new script to extend the
Bird
script. This time it is calledBlackBird
. - Do not forget to adjust line four to extend the
Bird
script and notMonoBehaviour
.public class BlackBird : Bird {
- This script has two variables. The first is the size of the explosion and the second is its strength.
public float radius = 2.5f; public float power = 25f;
- Once more we override the
DoSpecial
function, first marking that we did it. Next, we usePhysics.OverlapSphere
to acquire a list of all of the objects that are within the range of the bird's explosion. The function then loops through the list, skipping any empty slots and those without rigidbodies. If the object does exist and has a Rigidbody...