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
.
- Add two GameObjects of your choice.
- I suggest naming them
GoodOrb
andBadOrb.
- To GoodOrb, add a tag name of
GoodOrb.
- To BadOrb, add a tag name of
BadOrb.
- Create a prefab of each.
- Randomly add about 5 of each prefab to Scene1 and Scene2.
- 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
by 1, and GoodOrb will disappear from the Scene.
An analysis of the code we saw in the preceding code screenshot is as follows:
Line 38: void OnTriggerEnter(Collider other)
- This is a copy and paste from the example code in the Scripting...