Example #1
0
    // Use this for initialization
    void Start()
    {
        ui = FindObjectOfType <UIManager>();
        if (!ui)
        {
            Debug.Log("Failed to load UI Manager in GameManager");
        }
        pc = FindObjectOfType <PlayerControl>();
        if (!pc)
        {
            Debug.Log("Failed to find player control in GameManager");
        }
        leaderBoard = FindObjectOfType <LeaderboardManager>();
        if (leaderBoard)
        {
            highscore = leaderBoard.GetHigh();
            ui.UpdateHighScore(highscore);
        }


        buildings = FindObjectsOfType <BuildingMover>();
        spawn     = GetComponent <MasterSpawn>();

        LoadLevelData();

        StartLevel(level);
    }
Example #2
0
    void ChangeLane()
    {
        if (gameObject.transform.position.y > -4.5f)
        {
            int laneIndex;
            laneX = MasterSpawn.GetInitialX();
            for (laneIndex = 0; laneIndex < laneX.Length; laneIndex++)
            {
                if (Mathf.Abs(transform.position.x - laneX[laneIndex]) < 0.01)
                {
                    break;
                }
            }

            if (laneIndex == laneX.Length)
            {
                return;
            }

            if (laneIndex == 0)
            {
                MoveX(laneX[1]);
            }
            else if (laneIndex == laneX.Length - 1)
            {
                MoveX(laneX[laneX.Length - 2]);
            }
            else
            {
                int randDirection = Random.Range(0, 3);
                if (randDirection < 1)
                {
                    MoveX(laneX[laneIndex - 1]);
                }
                else
                {
                    MoveX(laneX[laneIndex + 1]);
                }
            }
        }
    }