Alright, I just made a timer that starts counting up on start up. What I need is every time the racer hits an object, it adds or subtracts time from the timer depending on the object. How do I come by this? I assume it is an OnCollisonEnter or OnTriggerEnter function but I am lost from there. Please help, I am quite new at this!
var timerText:GUIText;
var startTime:float = 0;
function Update () {
timerText = gameObject.GetComponent(GUIText);
timer = startTime + Time.time;
timerText.text = FormatTime (timer);
}
function FormatTime (time : float){
var minutes : int = Mathf.Floor(time / 60.0);
var seconds : int = Mathf.Floor(time - minutes * 60.0);
var milliseconds = time - Mathf.Floor(time);
milliseconds = Mathf.Floor(milliseconds * 1000.0);
var sMinutes = "00" + minutes.ToString();
sMinutes = sMinutes.Substring(sMinutes.Length-2);
var sSeconds = "00" + seconds.ToString();
sSeconds = sSeconds.Substring(sSeconds.Length-2);
var sMilliseconds = "000" + milliseconds.ToString();
sMilliseconds = sMilliseconds.Substring(sMilliseconds.Length-3);
timeText = sMinutes + ":" + sSeconds + ":" + sMilliseconds;
return timeText;
}
//Make sure you make the “Object” that makes your time, add OR subtract to make sure that it is set to “IsTigger”
//When I was learning unity3d I was told that ONE of the Object that you are going to enter HAS to have a Rigid body Im am not sure why
//Make sure you have the tag set to the “Object”…
//Hope this helps
//If not email me - logang730@gmail.com -
function OnTiggerEnter( other : Collider) {
if(other.tag == “AddTime”) { //Make A tag that is “AddTime”
startTime += 10; //Change to how much the time it adds
}
if(other.tag == “subtractTime”) { //Make A tag that is “subtractTime”
startTime += -10; //Change to how much the time it adds
Well what you’re going to want to do is find a way to differentiate your different objects. Like adding tags to them. Then you can use an OnCollisionEnter and check to see what it needs to do from there like
So I have the timer script above connected to a GUIText called “clock”. Does the collision text need to be separate and connected to the car or the objects? Also, if it is supposed to be separate, how do I manipulate the GUIText so that it shows the additions or subtractions? Thanks for the swift responses guys!