- Home /
Have a Timer Counts To 5 sec. Then Make a Sphere Appear While Using Instantiate
Hey guys I need help on a game that I am helping to create. It requires me to have a sphere on a plane of which I need to instantiate. This sphere would appear in the center of the plane after 5 seconds. The sphere is also a prefab. This is what I have so far:
var timer;
Var Totalseconds;
function createtimer (timerID, Time) {
Timer = document.getelementbyID(TimerID) ;
Totalseconds = Time;
UpdateTimer ( )
window.settimeout( "Tick()", 1000) ;
}
function Tick ( ) {
TotalSeconds -= 1;
UpdateTimer ( )
window.settimeout ("Tick ()", 1000 ;
}
Function Tick ( ) {
if (Tpta;secpmds <= 0 {
// Trigger Function (Instantiation)
TotalSeconds -=1;
UpdateTimer ( )
Window.setTimeout ("Tick ( )", 1000) ;
}
//Timer Countdown on runtime, Object instantiates upon countdown completion as "tech demo"
Thank you very much to this community and anyone who can help. :)
Answer by Bunny83 · Sep 15, 2012 at 02:22 AM
Ok some points:
Unity uses UnityScript and not ECMAScript (aka Javascript). UnityScript has a similar syntax like Javascript, but is a different language.
Unity isn't a website. You can't use a "window" object like you do in a webpage. The environment in a browser looks way different than in Unity.
UnityScript is (like Javascript) case-sensitive, so "Var" and "var" is not the same thing.
You should give every variable a type or you might get in trouble since the compiler can't tell the type at compile-time. It is possible to use dynamic variables, but they are quite slow.
To execute a function at a specific interval you can use InvokeRepeating