diff options
author | Marvin Borner | 2018-05-23 17:39:17 +0200 |
---|---|---|
committer | Marvin Borner | 2018-05-23 17:39:17 +0200 |
commit | 47c3a3275c5eb110c10933bc3dceb5eb3b89eb72 (patch) | |
tree | f74d8562441d7bcbf5c5d8f39d8eed3578161426 /Assets/RepeatingBackground.cs |
Added basic jumping and background moving
Diffstat (limited to 'Assets/RepeatingBackground.cs')
-rw-r--r-- | Assets/RepeatingBackground.cs | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/Assets/RepeatingBackground.cs b/Assets/RepeatingBackground.cs new file mode 100644 index 0000000..4722ec2 --- /dev/null +++ b/Assets/RepeatingBackground.cs @@ -0,0 +1,30 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class RepeatingBackground : MonoBehaviour { + + private BoxCollider2D groundCollider; + private float groundHorizontalLength; + + // Use this for initialization + void Start () + { + groundCollider = GetComponent<BoxCollider2D>(); + groundHorizontalLength = groundCollider.size.x; + } + + // Update is called once per frame + void Update () { + if (transform.position.x < -groundHorizontalLength) + { + RepositionBackground(); + } + } + + private void RepositionBackground() + { + Vector2 groundOffset = new Vector2(groundHorizontalLength * 2f, 0); + transform.position = (Vector2)transform.position + groundOffset; + } +} |