I’m new to Unity and currently doing a Unity Learn course. The videos are down right now, so I’m working on the functions of my personal project, but I’m having trouble increasing the scrolling speed. The code I have works for everything except increasing speed. For the first few seconds of the game, the speed increases. However, within a few seconds, the speed remains constant and I don’t even get the Debug.Log information anymore. Currently, I have:
void IncreaseSpeed()
{
timer += Time.deltaTime;
//increase speed over time
if (timer > levelWaitTime)
{
speed += difficultyIncrease;
Debug.Log("move left speed:" + speed);
timer = timer - levelWaitTime;
}
}
In my update function, I also call two other functions, but as far as I can tell, it shouldn’t get stuck in either other functions. One function moves the objects and the other one destroys them when their out of bounds.
I went in and updated my message right before you replied with everything except the variables at the top, but it looks like you were faster than I was. Hopefully my edit helps and thank you again for your time.
I’m just trying to get the full picture of what’s going on here. Basically, it seems like this is supposed to be a gradual level difficulty increasing thing - but if speed is just a member variable of this object that goes left until it gets destroyed, then the overall difficulty of the level is not going to go up. Each newly spawned object (I assume you’re Instantiating these somewhere?) will simply start with whatever the normal starting speed is from your prefab.
Question - when you say you are not getting the log anymore - are you sure you’re actually not? Maybe you just have the “Collapse” toggle turned on in your console, so it is grouping the identical logs together?
You’re right about the console. I should have thought of that. What I’m seeing now that I’ve unclicked collapse makes sense with what you’re saying.
I have a separate script that spawns items. I’ll try timing the speed in that script and then calling it in this script. Since I already increased the number of spawns over time in the other script, it should work.