Timer & if's
So, i have a really weird problem. i made a sprite array with 20 slot and i have a videoplayer in the scene. i want at some specified point of video, show one of the sprite in image that placed in the scene. but because my timer value change so fast, most of my conditions won't work because can't be detected so fast and i don't know how to fix it. Here's my code in Update function:
string useSecond;
foreach (VideoPlayer video in videos) {
useSecond = (video.time % 60).ToString ("f2");
show.text = useSecond;
if (useSecond == "6.73") {
showMoves.sprite = moves [1];
} else if (useSecond == "7.63") {
showMoves.sprite = moves [2];
}else if (useSecond == "8.67") {
showMoves.sprite = moves [3];
}else if (useSecond == "9.67") {
showMoves.sprite = moves [4];
}else if (useSecond == "10.67") {
showMoves.sprite = moves [5];
}else if (useSecond == "11.67") {
showMoves.sprite = moves [6];
}else if (useSecond == "12.23") {
showMoves.sprite = moves [7];
}else if (useSecond == "13.30") {
showMoves.sprite = moves [8];
}else if (useSecond == "14.20") {
showMoves.sprite = moves [9];
}else if (useSecond == "15.20") {
showMoves.sprite = moves [10];
}else if (useSecond == "16.30") {
showMoves.sprite = moves [11];
}else if (useSecond == "17.23") {
showMoves.sprite = moves [12];
}else if (useSecond == "17.87") {
showMoves.sprite = moves [13];
}else if (useSecond == "18.87") {
showMoves.sprite = moves [14];
}else if (useSecond == "20.03") {
showMoves.sprite = moves [15];
}else if (useSecond == "21.23") {
showMoves.sprite = moves [16];
}else if (useSecond == "22.37") {
showMoves.sprite = moves [17];
}else if (useSecond == "23.47") {
showMoves.sprite = moves [18];
}else if (useSecond == "23.50") {
showMoves.sprite = moves [19];
}
}
Answer by tormentoarmagedoom · Jul 29, 2018 at 10:47 AM
Good day.
I'm sure there is a better option, but i did something similar in the past, and found and "easy solution".
As always want to have all the sprites in the same order, you can have all of them in scene all one over another
(But in exactly same position and commence all SetActive(false))
Placed in the inspector icheracy with the correct order, so you first see the move [1]
Then make the timer become a float value with float.Parse, so you can compare it.
And when time > 6.73f
you can SetActive(true) all of them . (the first sprite will be on top and you will se it)
Then when timer > 7.63f
You cand estroy ir SetActive(false) the first spritew. (So you will se second sprite)
And go doing SetActive(false) 1 by 1 when the time is > than the timer value.
Understand ?
Bye :D
Thanks for answering but i solved it. it doesn't matter how i make conditions for time, it will always going to jump from one or two of my conditions. so i use the integer number of time and then invoke the function to show the right image for that time. if the time is 6 then i invoke the right function after 0.73sec. that's not good way for coding but it works for now and that is what i want. Thanks again.