Hello, I am trying to Mathf.Lerp some float values in a custom action. I am doing this:
override public float Run ()
{// Do the graduate changes
t = 0f;
while (t <= 1) {
for (i = 0; i < 4; i++) {
for (int j = 0; j < 5; j++) {
CM4x5 [i, j] = Mathf.Lerp (iniCM4x5 [i, j], final_CM4x5_array [i, j], t);
}
}
t += Time.deltaTime / timeOfChange;
Debug.Log (t + " " + CM4x5 [0, 0]);
return defaultPauseTime;
}
return 0f; // Wait time = 0s
}
But the Debug.Log only output once with t = 0.003599046. How can I make it run until t > 1?
Thanks.
It looks like you're new here. If you want to get involved, click one of these buttons!
Comments
I got the solution from this post:
https://www.adventurecreator.org/forum/discussion/9329/walk-to-the-point-own-action
But I got another question: How to implement the "wait until finish?" option for both the cases of checked and checked?
"defaultPauseTime" will cause the Action to be re-run the next frame.
To have an Action run every frame until a given max time, initialise the timer when the Action is first run, e.g.:
What counts as "finished" will depend on the Action itself. If it's unchecked, the behaviour of "official" AC Actions is that it will run for one frame only - so it'll always return "0f".
If you want the Action to have an effect over multiple frames, but have the Action itself only run for a single frame, then move the effects of the Action into a separate C# script and have the Action trigger a function within that script.
See, for example, the way the Camera: Fade Action (ActionFade.cs) calls the MainCamera's FadeIn / FadeOut functions to perform the actual fading effect.