How to update scoreline on a HIT?

Hello,

I am working on a Projectile Motion and when the ball hits the enemy I wish to increase score whenever the enemy is killed. Hence I have an Enemy prefab, which is instantiated through script (on FIRING).

Code:

Collision checking script (cannontrans.js)

var ene_hit : la_point;
function OnCollisionEnter(hit : Collision)
{
   randomrange();
   if(hit.gameObject.tag == "cannonball")
   {
   		transform.position = Vector3(r_enepos,2,0);
   		
   }
}

Code Explanation:

Whenever it gets a hit I wish to move position of the object. Hence here I would also like to increase the score to display on the UI using OnGUI function. The above code it attached onto the enemy Prefab I was talking earlier about.

Perception:

I wish to increase the score on a different script. The reason is - I have lots of scenes and every scene requires it own scoreline.

Request:

I humbly request someone to help me on this issue. I am not sure how to proceed. My main aim at the end of the day is to have the prefab initiated through script and update the score line whenever there is a hit. Kindly let me know if I have to detailed certain aspects out too.

cannontrans.js → C code - 65 lines - codepad

THANK YOU VERY MUCH

var obj : GameObject;

//In collision enter:

var scoreScript = obj.GetComponent(SCRIPT_NAME);

scoreScript.score = scoreScript + 1;
// End collision enter;

//In SCRIPT_NAME on the obj that is where the score is or w/e.
var score = 0;

//OnGUI;
{
//Draw w/e with the score var.
}

This should work… Mostly psuedocode, but basically you pass in the object that has the GUI on it, store it as obj. Then you access the component (The script) of the object that contains the GUI and in result, the score variable, then just ++ it.

I think this is what you want, no?

Seems the code you have already handles the random movement.

If not, reply, I’ll try to help further.