Game Development Reference
In-Depth Information
if (hit.collider.gameObject.name == ("Sphere_001"))
{
Destroy(hit.collider.gameObject);
} else if (hit.collider.gameObject.name == ("Sphere_002"))
{
Destroy(hit.collider.gameObject);
} else if (hit.collider.gameObject.name == ("Sphere_003"))
{
Destroy(hit.collider.gameObject);
} else if (hit.collider.gameObject.name == ("Sphere_004"))
{
Destroy(hit.collider.gameObject);
} else if (hit.collider.gameObject.name == ("Sphere_005"))
{
Destroy(hit.collider.gameObject);
}
}
}
But you see how tedious and bulky the code gets with only a few evil spheres. What if you had a
much bigger number of evil spheres?
Tags
Tags are an important scripting tool that allow you to sort and identify groups of game objects such
as evil spheres, which in turn simplifies your code.
In the Hierarchy, select Sphere_001 and take a look at the Inspector, where you'll see an option for
Tag near the top, just below the game object name (Figure 7-19 ).
Figure 7-19. Tag drop-down menu selector in the Inspector
 
Search WWH ::




Custom Search