How do I count Hits ??

I created a small terrain with high walls and placed a long spinning cube in the center. Occasionally, a colored sphere will randomly spawn in one of the corners on the terrain and then the sphere will move slowly to the center. When the spinner hits them, they bounce off the walls and each other and occasionally get hit over the wall and fall to their death…I destroy them if they get too far below the terrain. No problem with any of this, it all works fine.


I want to destroy them a second way. If the spinner hits any of the spheres, say, five times, I want the sphere to be destroyed…sort of like taking damage but based on the number of hits rather than amount of damage. I’ve been researching this and I don’t begin to know how to count when one of my spheres gets hit five times. I’ve been trying all sorts of stuff with my colliders and so forth, no luck.

Here’s how I generate the spheres in one of the corners if that helps (I simply plug this into one of a switch statement…once case for each corner and one case for add nothing:

		sphere = GameObject.CreatePrimitive (PrimitiveType.Sphere);
		sphere.transform.position = new Vector3 (27f, .5f, 27f);
		sphere.GetComponent<Renderer> ().material.color =;
		sphere.AddComponent<Rigidbody> ();
		sphere.AddComponent<Movement> ();

Here’s my movement control:

Vector3 goToHere = new Vector3 (15,0.5f,15);
float speed = 3f;

void FixedUpdate () 
	GetComponent<Rigidbody> ().AddForce (transform.forward*speed);

add a collider to one of the objects, make sure both have rigid bodies:

void OnTriggerEnter(Collider other){

I’m pretty sure this is exactly what I need but I’m having a hard time working out all the details. I’ve been looking up examples of this and trying to sort through them but I still have some questions.

It looks like a standard function but I’m not sure how it gets called…does it need to be invoked/called from “Update” or “FixedUpdate” or is this automatic?

I’m not sure about how that “other” fits in here and I can’t quite get things to “count” correctly…I can get it to count…just not on a hit/collision.

I’m still working on it…looking for more examples to work with.