Time for action – creating a good and bad prefab

We need to create two prefabs. The names aren't too important because we'll be using tags in our code. The tag names are important, which are GoodOrb and BadOrb.

  1. Add two GameObjects of your choice.
  2. I suggest naming them GoodOrb and BadOrb.
  3. To GoodOrb, add a tag name of GoodOrb.
  4. To BadOrb, add a tag name of BadOrb.
  5. Create a prefab of each.
  6. Randomly add about 5 of each prefab to Scene1 and Scene2.
  7. As an example, see the screenshot at the beginning of this chapter.

What just happened?

We now have the ability to increase our Score or lose Lives

Scoring for the win

All it takes to win is for the value in the variable score to be 2.

To increase score, Player will collide with a GoodOrb which increases score

Get Learning C# by Developing Games with Unity 3D 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.