- Home /
Question by
AJAWESOME900 · Jan 21 at 03:36 AM ·
unity 2dbackgroundinfinite runnerfloorscroller
How to increase the speed of the background as time goes on (unity 2d),How to increase the speed as time goes on (unity 2d)
So I want the speed of the background to increase as time goes on. For example, every 20 seconds the speed is increased by 20%. I can't figure out how to do this and any help would be appreciated. Here's my script :).
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class FloorScroller : MonoBehaviour { public BoxCollider2D collider; public Rigidbody2D rb;
private float width;
private float scrollSpeed = -7.5f;
// Start is called before the first frame update
void Start()
{
collider = GetComponent<BoxCollider2D>();
rb = GetComponent<Rigidbody2D>();
width = collider.size.x;
rb.velocity = new Vector2(scrollSpeed, 0);
}
// Update is called once per frame
void Update()
{
if(transform.position.x < -width)
{
Vector2 resetPosition = new Vector2(width * 2f, 0);
transform.position = (Vector2)transform.position + resetPosition;
}
}
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613051936im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Horizontal / Vertical duplicating object 2 Answers
Help with Spawning & Destroying Background Objects in 2D 2 Answers
Unity2D Parallax Scrolling approach concern -1 Answers
Parallax Lag issue... 0 Answers