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 ...
Get Unity Android Game Development by Example Beginner's Guide now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.