VR MV – Update #5

So I have tried to merge the movement and appearing codes into one but have come across a few issues whilst doing so. I wanted to use the position of the object to determine when it appears and disappears but removing the “Time.time” variable and inserting the rest of the code into the if statement from the position tracking would make the object just disappear and appear instantly, but I want them to gradually.

I then decided to do it time based and use separate if statements to get them to work, but they required precise timing of exactly when they’re meant to appear and disappear. Over the duration of the 192 seconds long song, that would mean a lot of code for the same event happening. This idea did work, but there were too many fluctuations when the program would start and when the counter would start timing. This meant each time the program would run from the beginning, there was no guarantee the vehicles would be in the right place at the right time for the duration of the song.

My third idea was to use while loops instead. I made 2 while loops with the if statements for the original Time.deltaTime variable inside so that the gradual appearance and disappearance would still happen. While the vehicles are before or after a certain point, the fading would occur accordingly. Unfortunately, whilst the code editor says this works, Unity seems to think otherwise and instantly freezes and crashes when I press the play button. So it seems I can’t use this idea and may have to use the extensive if statements for timings, which will be slightly innacurate, unless I can figure out a different way to get this working.