Time for action – creating the yellow bird
Because of the power of inheritance, the script we are creating here consists of only a handful of lines of code:
- Start by creating the yellow bird in the same way as the red bird, using the
YellowBird
model instead. - Instead of using the
Bird
script, we will create theYellowBird
script. - This script needs to extend the
Bird
script, so replaceMonoBehaviour
withBird
on line four. It should look similar to the following code snippet:public class YellowBird : Bird {
- This script adds a single variable that will be used to multiply the bird's current velocity.
public float multiplier = 2f;
- Next, we override the
DoSpecial
function and multiply the bird'srigidbody.velocity
when it is called:protected override void DoSpecial() { didSpecial = true; rigidbody.velocity *= multiplier; }
- Return to Unity, add the script to your new bird, and turn it into a prefab. Add some to the list on your slingshot to use the bird in your level.