Esempio n. 1
0
    public void OnSpawnNewLane(Lane origin)
    {
        Lane prefabTypeToSpawn = Utilities.RandomFromArray(lanePrefabs);

        Lane newLane = Instantiate(prefabTypeToSpawn.gameObject).GetComponent <Lane>();

        newLane.transform.position = origin.EndPoint.position - newLane.StartPoint.localPosition;

        newLane.OnSpawnNextLane += OnSpawnNewLane;
        newLane.Spawn();
        spawnedLanes.Add(newLane);

        if (spawnedLanes.Count > maxAllowedLanes)
        {
            Lane firstLane = spawnedLanes[0];
            firstLane.OnSpawnNextLane -= OnSpawnNewLane;
            firstLane.Despawn();
            spawnedLanes.Remove(firstLane);
        }
    }