Okay I suspect I am just missing a variable or misplacing some part of these two codes. The scenario is I have a timer that is counting down. When I hit an object I want to add some more time to the timer. BUT with the code I have now, the currentTime will update very briefly, then revert back to the countdown time. I know the currentTime is stored correctly but I think the UpdateTimerText function is confused and I just can’t see what to do. Thanks for the help. You guys are awesome.
Script A - Timer.js
// the textfield to update the time to
private var textfield:GUIText;
// time variables
public var allowedTime:int = 90;
public var currentTime;
function Awake()
{
currentTime = allowedTime;
// retrieve the GUIText Component and set the text
textfield = GetComponent(GUIText);
UpdateTimerText();
// start the timer ticking
Tick();
}
function Tick()
{
// while there are seconds left
while(currentTime > 0)
{
// wait for 1 second
yield WaitForSeconds(1);
// reduce the time
currentTime--;
UpdateTimerText();
}
}
function UpdateTimerText()
{
// update the textfield
textfield.text = currentTime.ToString();
}
Script B - ObjectInteraction.js
`private var textfield:GUIText;
public var currentScore: ScoringScript;
function OnCollisionEnter(collision : Collision) {
if (collision.gameObject.name == "Capsule"){
currentTime.currentTime += 10;
currentTime.UpdateTimerText();
}
}