- Home /
Increase Static Var gradually
So Basically I have a static var (globalSpeed). I need it to gradually increase every frame or just over time really. I could achieve this really easily when it was a normal variable but once I changed it to a static it doesn't seem to work any more. Here's what I'm working with and I'm sure its horribly wrong.
static var globalSpeed;
function Update () { globalSpeed += 1;
}
Basically here's what I'm trying to achieve:-
In my game the character is running in place and all the scenery objects and backgrounds are scrolling left to give the appearance that the character is moving. The scenery objects are randomly generated at the right side of the screen off camera, and then destroyed when they reach the left side off camera. I need to set a global speed so that all the scenery items scroll left at the same speed. I also need that speed to gradually increase slowly over time to give the impression that the character is speeding up.
Perhaps you could give me some pointers on how to better achieve this?
Sorry about the long winded question. Thanks in advance!
Answer by Zumwalt_old · Sep 26, 2010 at 04:22 AM
First do a Debug.Log(globalSpeed) and see if the value is actually increasing or not.
Ugh, I feel like an idiot. The problem was the speed was set only once on the object that needed to be moved. I set it up update every frame and bingo. Thanks, I'll probably never post again as punishment for my idiocy.
Don't worry, LuisG, as it says in the Unity Answers FAQ, "no question is too trivial or too 'newbie'" for Unity Answers. Don't stop posting; you've only just begun!