Hello all,
I have been trying for quite a while to track down a very annoying problem in my script and I finally found out that the troublemaker is apparently InvokeRepeating. I made a simple script to demonstrate the problem I am facing.
var Test : int = 0;
var Rate : float = 0.2;
function Update ()
{
if(Input.GetKeyDown("mouse 0"))
InvokeRepeating("TestCounter", 0, Rate);
if(Input.GetKeyUp("mouse 0"))
CancelInvoke();
}
function TestCounter()
{
Test++;
}
This is a script that should advance the counter when left mouse button is pressed at a rate specified by the Rate variable. It does that at all times except on the first frame. When it starts counting, depending on the rate of repeat, it advances 6 or more times. Results I got are that at a rate of 0.2 if I just super quick press and release mouse button it counts 6… if rate is 0.5 (to absolutely make sure that button is pressed for a shorter duration of time than the rate is) it still counts 3-4 for just one click… all consequent counting is correct, but the first click is never 1…
Can someone tell me what is going on and how I can overcome this problem? I assume that I am doing something wrong, and I tried really hard to figure it out, but I just can’t, since I’m a newbie
Thanks!