I need to get my script to enable when I walk in a trigger, the time to start when I enter the trigger.
It starts whenever I launch the game.
#pragma strict
var startTime : float;
var score : int;
var scoreText : UnityEngine.UI.Text;
function OnTriggerEnter (player : Collider)
{
startTime=Time.time;
}
function Update ()
{
score = Time.time;
}
function CalculateScore () : int
{
return Time.time;
}
function OnGUI ()
{
scoreText.text = "Time Score: " + " " + score.ToString();
}
Cynikal
2
Note: I’ll write this out in C#, but shouldnt be hard for you to convert.
bool TimerStarted = false;
void OnTriggerEnter (blah blah)
{
if (!TimerStarted) TimerStarted = true;
}
private float _timer = 0f;
public float TimeIWantInSeconds = 10f;
void Update()
{
if (TimerStarted)
{
_timer += Time.deltaTime;
if (_timer >= TimeIWantInSeconds)
{
//Do whatever since the time has elapsed.
}
}
}
Here’s a tool that might be useful: