ScrollingObject.cs
795 Bytes
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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[RequireComponent(typeof(Rigidbody2D))]
public class ScrollingObject : MonoBehaviour
{
private Rigidbody2D rb2d;
// Use this for initialization
void Start ()
{
//Get and store a reference to the Rigidbody2D attached to this GameObject.
rb2d = GetComponent<Rigidbody2D>();
rb2d.bodyType = RigidbodyType2D.Kinematic;
//Start the object moving.
rb2d.velocity = new Vector2 (GameControl.Instance.scrollSpeed, 0);
}
void Update()
{
// If the game is over, stop scrolling.
if(GameControl.Instance.gameOver == true)
{
rb2d.velocity = Vector2.zero;
}
else
{
rb2d.velocity = new Vector2 (GameControl.Instance.scrollSpeed, 0);
}
}
}