Hi. I’m a semi - beginner on Unity. Recently, I have been trying to make a rage game. Basically the player has to move a object and dodge the incoming obstacles. I created three variables, one for increasing the obstacle speed, one for the current speed and one for the max speed. However if I do the current speed += increase obstacle speed * time.deltatime inside the Update() function, it does not increase. I was wondering if anyone has a solution to this?
The code I’m using: (the obsSpeed is set to 5 and the increaseObsSpeed is set to 1)
//Obstacle
public Rigidbody2D rb;
public float timeToIncreaseSpeed;
//Obstacle Speed
public float obsSpeed;
public float increaseObsSpeed;
public float maxObstacleSpeed;
//Obstacle effect
public GameObject obsEffect;
private void Update()
{
obsSpeed += increaseObsSpeed * Time.deltaTime;
transform.Translate(Vector2.down * obsSpeed * Time.deltaTime);
if(rb.position.y <= -9f)
{
Destroy(gameObject);
}
}
private void OnTriggerEnter2D(Collider2D collision)
{
if(collision.CompareTag("Player"))
{
//Create effect
Instantiate(obsEffect, transform.position, Quaternion.identity);
Destroy(gameObject);
}
}