Ok My Score Is not Displaying in game it hits all the debug nodes but it does not update the score on the GUI.
Score Keeper Script:
@script ExecuteInEditMode()
var currentScore : int = 0;
var time : float = 0.0;
var hitCrosshairTexture : Texture;
private var alphaHit : float;
var hitSound : AudioClip;
var mySkin : GUISkin;
var pointsToNextRank : int = 50;
var rank : int = 0;
var rankSound : AudioClip;
function Update () {
if (time > 0){
time -= Time.deltaTime;
}
alphaHit = time;
}
function DrawCrosshair(){
yield WaitForSeconds(0.1);
time = 1.0;
audio.PlayOneShot(hitSound, .5);
}
function addScore(value : int){
Debug.Log("Score Added?");
yield WaitForSeconds(0.2);
currentScore += value;
if(currentScore >= pointsToNextRank){
rank++;
PlayAudioClip(rankSound, transform.position, 1.0);
pointsToNextRank += currentScore;
}
}
function PlayAudioClip (clip : AudioClip, position : Vector3, volume : float) {
var go = new GameObject ("One shot audio");
go.transform.position = position;
var source : AudioSource = go.AddComponent (AudioSource);
source.clip = clip;
source.volume = volume;
source.pitch = Random.Range(0.95,1.05);
source.Play ();
Destroy (go, clip.length);
return source;
}
function OnGUI(){
GUI.skin = mySkin;
var style1 = mySkin.customStyles[0];
GUI.Label (Rect(40, Screen.height - 80,100,60)," SCORE :");
GUI.Label (Rect(100, Screen.height - 0,11160,0),"" + currentScore, style1);
GUI.Label (Rect(40, Screen.height - 110,100,60)," LVL :");
GUI.Label (Rect(100, Screen.height - 110,160,60),"" + rank, style1);
GUI.color = Color(1.0, 1.0, 1.0, alphaHit);
GUI.DrawTexture (Rect ((Screen.width - hitCrosshairTexture.width)/2, (Screen.height - hitCrosshairTexture.height)/2, hitCrosshairTexture.width, hitCrosshairTexture.height), hitCrosshairTexture);
}
And Zombie Health Script:
var maximumHitPoints = 100.0;
var hitPoints = 100.0;
var deadReplacement : Rigidbody;
var GOPos : GameObject;
private var scoreManager : ScoreManager;
function Start(){
var GO = gameObject.FindWithTag("ScoreManager");
scoreManager = GO.GetComponent("ScoreManager");
}
function ApplyDamage (damage : float) {
if (hitPoints <= 0.0)
return;
// Apply damage
hitPoints -= damage;
scoreManager.DrawCrosshair();
// Are we dead?
if (hitPoints <= 0.0)
Replace();
}
function Replace() {
// If we have a dead barrel then replace ourselves with it!
if (deadReplacement) {
var dead : Rigidbody = Instantiate(deadReplacement, GOPos.transform.position, GOPos.transform.rotation);
scoreManager.addScore(1);
Debug.Log("SCORED");
// For better effect we assign the same velocity to the exploded barrel
dead.rigidbody.velocity = rigidbody.velocity;
dead.angularVelocity = rigidbody.angularVelocity;
}
// Destroy ourselves
Destroy(gameObject);
}