Hello programming peeps, hope you guys doing well. I been trying to figure this out for a while but I haven’t been able to yet. Well here’s the scenario: I have made a score script which it adds 20 to the score once an enemy is destroyed. It works, but just when I go to the next level, but I want it to add immediately after being destroyed. Here are my scripts:
in cannon.js :
var explosion : Transform;
static var score : int = 0;
function OnTriggerEnter( hit : Collider )
{
if(hit.gameObject.tag == "playerProjectile")
{
Destroy(hit.gameObject);
var exp = Instantiate(explosion, gameObject.transform.position, Quaternion.identity);
score += 20;
Destroy(gameObject);
}
}
And this is what I got in my GUI.js
//main vars
var clearedPrefab : Transform;
var controlTexture : Texture2D;
var playerScore = MoveAround.score;
function OnGUI ()
{
// to count the number of enemies
var coinCount : int = GameObject.FindGameObjectsWithTag("Cannons").Length;
//variable for the score lives box
var lifeBox = " Lives Left: "+Health.LIVES+"\n Enemies Left: "+coinCount+"\n Score: "+playerScore;
//score lives box
GUI.Box (Rect (Screen.width - 152,10,150,50), lifeBox);
}
So this is my code, can you tell me if I am doing something wrong? Like I said, the score does adds the 20 points, but only after I go to the next level(or scene).
cheers =]