Regards,
I’m new to unity. I searched the whole forum for an answer on how to keep track of passed time. say an alarm system for exapmle, so i can do things on a timely basis.
To give you an overview of what i’m going to do, assume that I have a script that checks for user input. when input is recieved, I want to move a cube for, let’s say, 3 seconds, and disable input checking. after 3 second, i want to enable input checking again, and do some other things. I’m sure you have faced this before.
I tried to use yield to wait, but it says that yield can’t be executed inside update() or something like that. i feel a little dumb here
, but hey, i’m new. so please bear with me 
Sounds like you need two things here. First, you need a state variable for your cube. Something like isMoving : boolean should do the trick. Use that to check if input should be handled or not. Second, you need a timer to keep track of how long the cube remains in that state. Try this snippet as a starting point:
var isMoving : boolean = false;
var moveStart : float;
var moveDuration : int = 3;
function Update()
{
if([whatever input check you need] !isMoving)
{
isMoving = true;
moveStart = Time.time;
}
if(Time.time - moveStart > moveDuration)
isMoving = false;
if(isMoving)
DoMove();
}
I’m sure there is a more efficient way to condense what is there, but I think you’ll get the gist of what you need to do. I’ve actually created a simple timer class, as I realised that time checks come into play quite a bit in games. I even think there is a timer script on the wiki, so look into that to if timing becomes prevalent in your game.
Maker16, you’re my man. thanks for the sample code, as it gives me exactly what i want. i thought maybe there’s a buit-in timer system that care for such situations. but it looks that every time dependent event should be compared to a general reference, like Time.time …
Tnx again.