Time for action – creating the blue bird
The blue bird will again make use of inheritance, reducing the amount of code that needs to be written to create the bird:
- Again, start building your blue bird the same way as the previous two, substituting the appropriate model. You should also adjust the Radius of the Sphere Collider component to align appropriately with the smaller size of this bird.
- Next, we create the
BlueBird
script. - Again, adjust line four so the script extends
Bird
instead ofMonoBehaviour
.public class BlueBird : Bird {
- This script has three variables. The first is a list of prefabs to spawn when the bird splits. Next is the angle difference between each new bird that will be launched. Finally is a value to spawn the birds a little ahead of their current position to keep them from getting stuck inside each other.
public GameObject[] splitBirds = new GameObject[0]; public float launchAngle = 15f; public float spawnLead = 0.5f;
- Next, we override the
DoSpecial
function and...