private void SpawnCars(HashSet <uint> occupiedIndices) { // Choose a few valid spots var carIndices = new HashSet <uint>(); do { var index = (uint)UnityEngine.Random.Range(0, CurrentRoom.tileMap.NumTiles); if (!occupiedIndices.Contains(index) && !carIndices.Contains(index) && CurrentRoom.tileMap.GetTileType(index) == TileType.Floor && index != playerMovement.Index) { carIndices.Add(index); var carObject = Instantiate(carPrefab, GameUtils.GetPosition(index), Quaternion.identity); carObject.transform.SetParent(carParent.transform); var car = carObject.GetComponent <CarMovement>(); car.InitPosition(index); var obj = new ObjectInstantiationData { Type = ObjectInstantiationType.Car, GameObject = carObject, Index = index, Rotation = Quaternion.identity }; CurrentRoom.Cars[index] = obj; } } while (carIndices.Count < 2); }
private void AddObjectInstantiationDataToList(ObjectInstantiationData obj, GameObject inst, IDictionary <uint, ObjectInstantiationData> dict, GameObject parent) { // Override the prefab game object with the instantiation var objWithInst = obj; objWithInst.GameObject = inst; dict.Add(obj.Index, objWithInst); inst.transform.SetParent(parent.transform); }