- Home /
Score Keeper / Kill Counter Help
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);
}
any one know any thing why possibly it dosent work?
Answer by frogsbo · Jan 29, 2014 at 04:49 AM
not very much seems to be happening in the update function.
troubleshoot that stuff by printing Time.time instead of score for a start to see if your GUI is updating.
If it is, try passing through the score value through update invisibly or something like that.
where a value is disappearing, always work up the code sequence with different values that you know are more reliable and intrinsic to unity, to test the parts of your code sequence
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Can someone help me fix my Javascript for Flickering Light? 6 Answers
Setting Scroll View Width GUILayout 1 Answer
How To Stop Destroyer From Destroying? 2 Answers