- Home /
Time.deltaTime always null
Trying to create a simple chronometer:
var minutes : int = 0; var seconds : float = 0.0;
function Update () {
seconds = seconds + Time.deltaTime;
if(seconds >= 60){
minutes++;
seconds = seconds - 60;
}
Debug.Log(minutes + " : " + seconds);
}
I always get an error:
NullReferenceException: Object reference not set to an instance of an object Boo.Lang.Runtime.RuntimeServices.InvokeBinaryOperator (System.String operatorName, System.Object lhs, System.Object rhs) Time.Update () (at Assets/Scripts/Time.js:6)
I also tried this tutorial and the code that was working fine in the video gave the same error for me again. Plus puting the Time.deltaTime in Debug.Log only shows Null...
So I am stuck at this now :(
Answer by Eric5h5 · Aug 24, 2011 at 08:11 PM
You can't call your script the same thing as a Unity class*, because then it's looking inside your Time script for deltaTime, which of course does not exist.
* Unless you distinguish between them by specifying UnityEngine.Time, but that's a bit of a pain.
Your answer
Follow this Question
Related Questions
How to add forward velocity to a Rigidbody2D? 2 Answers
Anyone Else wanna take a wack at the question ? Need help fixing a script error... 5 Answers
Object reference not set to an instance of an object? 1 Answer
NullReference Problem with pragma strict 1 Answer
How can i fix this weird error 2 Answers