-
Notifications
You must be signed in to change notification settings - Fork 0
/
BackgroundController.cs
52 lines (36 loc) · 1016 Bytes
/
BackgroundController.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
using UnityEngine;
using System.Collections;
/*
* File Name : BackgroundController.cs
* Author : Austin Khamsisavadty 100942529
* Last Modified : 10/30/2016
* Date Last Modified : 10/30/2016
* Description : Controls background
* Revision : 1.0
* */
public class BackgroundController : MonoBehaviour {
[SerializeField]
private float speed = 0.015f;
private Transform _transform;
private Vector2 _currentPosition;
//Initialization
void Start () {
_transform = gameObject.GetComponent<Transform>();
_currentPosition = _transform.position;
Reset ();
}
// Update is called once per frame
void Update () {
_currentPosition = _transform.position;
_currentPosition -= new Vector2 (speed, 0);
_transform.position = _currentPosition;
if (_currentPosition.x <= -20f) {
Reset ();
}
}
//Reset background to start once end is reached
private void Reset(){
_currentPosition = new Vector2 (20f, -0.03f);
_transform.position = _currentPosition;
}
}