GameController.cs 1.21 KB
Newer Older
1 2
using Assets.Scripts.MapGeneration;
using Assets.Scripts.Utils;
Naliwe GS committed
3
using UnityEngine;
Raphael committed
4
using System;
Naliwe GS committed
5 6 7 8 9 10 11

namespace Assets.Scripts
{
    public class GameController : MonoBehaviour
    {
        public static int PoolSize = 256;

12
        public GameObject Wall;
Naliwe GS committed
13
        public GameObject BG;
14

15 16
        private Map _map;

Naliwe GS committed
17 18 19
        private Vector3 size;
        private Transform tra;
        private int mult = 1;
20

Naliwe GS committed
21 22
        void Start()
        {
Naliwe GS committed
23 24
            size = BG.GetComponent<SpriteRenderer>().sprite.bounds.size;
            tra = BG.GetComponent<Transform>();
Raphael committed
25
            Screen.orientation = ScreenOrientation.LandscapeLeft;
Naliwe GS committed
26 27 28 29
        }

        void Update()
        {
Raphael committed
30
            Camera.main.transform.Translate(new Vector3(4f*Time.deltaTime, 0, 0));
31 32 33
            var rightBorder = Camera.main.ScreenToWorldPoint(new Vector3(Screen.width,
                Screen.height, 0)).x;
            var leftBorder = Camera.main.ScreenToWorldPoint(new Vector3(0, 0, 0)).x;
Naliwe GS committed
34

Raphael committed
35
            if (!(rightBorder > (size.x*mult) - 5)) return;
Naliwe GS committed
36 37

            BG = (GameObject) Instantiate(BG, new Vector3(size.x + tra.position.x - .5f, tra.position.y, 2), Quaternion.identity);
Raphael committed
38 39
            tra = BG.GetComponent<Transform>();
            mult++;
40
        }
Naliwe GS committed
41 42
    }
}