ok.im using the countdown found in this post
Unity Community – View topic - Adding Time to a Timer.htm
var startTime = 30.0;
function Update () {
//The time left for player to complete level
timeLeft = startTime - Time.time;
//Don't let the time left go below zero
timeLeft = Mathf.Max (0, timeLeft);
//Format the time nicely
guiText.text = FormatTime (timeLeft);
}
//Format time like this
//12(minutes):34(seconds).5(fraction)
function FormatTime (time) {
var intTime : int = time;
var minutes : int = intTime / 60;
var seconds : int = intTime % 60;
var fraction : int = time * 10;
fraction = fraction % 10;
//Build string with format
//12(minutes):34(seconds).5(fraction)
timeText = minutes.ToString () + ":";
timeText = timeText + seconds.ToString ();
timeText += "." + fraction.ToString ();
return timeText;
}
and now im using
timer.startTime += 30.0;
to add 30 s to my countdown when i kill a enemy.i use the character damage script
var hitPoints = 100.0;
var deadReplacement : Transform;
var dieSound : AudioClip;
var killsCounter : KillsCounter;
var timer : Timer;
function ApplyDamage (damage : float) {
// We already have less than 0 hitpoints, maybe we got killed already?
if (hitPoints <= 0.0)
return;
hitPoints -= damage;
if (hitPoints <= 0.0)
{
Detonate();
Kill();
}
}
function Detonate () {
// Destroy ourselves
Destroy(gameObject);
// Play a dying audio clip
if (dieSound)
AudioSource.PlayClipAtPoint(dieSound, transform.position);
// Replace ourselves with the dead body
if (deadReplacement) {
var dead : Transform = Instantiate(deadReplacement, transform.position, transform.rotation);
// Copy position rotation from the old hierarchy into the dead replacement
CopyTransformsRecurse(transform, dead);
}
}
function Kill() {
killsCounter.AddKill();
timer.startTime +=30.0;
}
static function CopyTransformsRecurse (src : Transform, dst : Transform) {
dst.position = src.position;
dst.rotation = src.rotation;
for (var child : Transform in dst) {
// Match the transform with the same name
var curSrc = src.Find(child.name);
if (curSrc)
CopyTransformsRecurse(curSrc, child);
}
}
ok, i dont have errors in the unity editor, but i dont see 30s more in the countdown when i kill my enemy.what im doing wrong.???