- Home /
Time class == null in Unity 4.3
Whenever I attempt to access Time.deltaTime, or any other member of Time, I get null. Prints, math, etc. with Time don't work. This is my code (below), but I also tried using the Scripting Reference Example code, and that didn't compile either. If anybody else has encountered this problem and has a solution or information that I could use, it would be much appreciated
var go : boolean;
var pages : int;
var times = new Array();
var average :double;
var disTime : String;
var sec : int;
var min : int;
var hour : int;
function Start () {
}
function Update () {
if(go)
{
sec += Time.deltaTime;
GetComponent(GUIText).text = "" + sec;
}
}
Do you have a class called Time in your project? Use the search bar to isolate if any.
Answer by tanoshimi · Dec 17, 2013 at 07:42 PM
deltaTime is a float. You're trying to use it to increment sec, which is an int. Try making sec a float (and also call ToString() in the Update function)
Sorry about that. I fixed the incompatibility after the post, and recompiled. It still doesn't acknowledge the existence of class Time.
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/Time.js:17)
The same error occurs when I try Time.time or other variables in that class.
Your script is called Time.js? Try rena$$anonymous$$g it to, say, $$anonymous$$yTime.js
I just face palmed. Thanks, I should probably avoid na$$anonymous$$g my scripts after classes.
Your answer