C# how to make things happens Through time?
Im making an space shooter that it has asteroids randomly spawning on the top of the scene that goes to the bottom of the scene, what i want to make is speed up the velocity of the fall of the asteroids. The Script i try but isn't working is something like this. Sorry for the trouble and Thanks in advance
public class AsteroidControl : MonoBehaviour {
float speedAsteroide;
float TimeForSpeedUp = 120f; // Time until the speed goes up , try to make like a timer
// Use this for initialization
void Start () {
speedAsteroid = 2f; //Initial speed of the asteroids
}
// Update is called once per frame
void Update () {
TimeForSpeedUp -= 1f * Time.deltaTime; // i thoght that this will make the TimeForSpeedUp go down in real seconds
if (TiempForSpeedUp == 0f) {
speedAsteroid = speedAsteroid + 1f;
TimeForSpeedUp += 120f;
} // and this if is to check if the TimeForSpeedUp is over make the speed go up and try to repeat it filling again the TiempForSpeed
I just put an audio souce on top of the 20# line to se if the timer is working and it is, i can hear the sound of the audio clip but the speed doesnt go up and the timer doesnt reset :/
you could always do it with a coroutine
IEnumerator $$anonymous$$yCoroutine()
{
for (int i = 0; i = 10; i++) //put the max number of times you want it to speed up where the 10
{
speedAsteroid += 1;
yield return new WaitForSeconds(TimeForSpeedUp);
{
}
that should make it speed up once every x seconds just remember to initialize it using
StartCoroutine("$$anonymous$$yCoroutine")
Your answer
Follow this Question
Related Questions
Respawn issues 2 Answers
,Why isn't the clock speed being affected by the float "clockSpeed"? 0 Answers
Space Shooter - Asteroids moving randomly 1 Answer
Time.deltaTime timer counting slowly 3 Answers
PowerUp Timer 0 Answers