Пример #1
0
    private void SpawnNpc(NpcAccessPoint accessPoint)
    {
        List <CompleteNpc> compatiblePrefabs = GetPrefabsForAccessPointType(accessPoint.type);

        if (compatiblePrefabs != null && compatiblePrefabs.Count > 0)
        {
            CompleteNpc randomNpc = compatiblePrefabs[Random.Range(0, compatiblePrefabs.Count - 1)];

            if (randomNpc != null)
            {
                List <NpcAccessPoint> compatibleDestinations = GetDestinationsForNpcType(randomNpc.Type, accessPoint);

                if (randomNpc != null && compatibleDestinations != null && compatibleDestinations.Count > 0)
                {
                    accessPoint.SpawnNpc(randomNpc.prefab, compatibleDestinations);
                    _availableAccessPoints.Remove(accessPoint);
                    randomNpc.Count++;
                }
                else
                {
                    Debug.LogWarning("Failed to spawn an NPC");
                }
            }
            else
            {
                Debug.LogError("An NPC is missing its NpcType component");
            }
        }
        else
        {
            Debug.Log("All NPCs types have been maxed out");
        }
    }
Пример #2
0
    private void SpawnNpc(NpcAccessPoint accessPoint)
    {
        List<CompleteNpc> compatiblePrefabs = GetPrefabsForAccessPointType(accessPoint.type);

        if (compatiblePrefabs != null && compatiblePrefabs.Count > 0)
        {
            CompleteNpc randomNpc = compatiblePrefabs[Random.Range(0, compatiblePrefabs.Count - 1)];

            if (randomNpc != null)
            {
                List<NpcAccessPoint> compatibleDestinations = GetDestinationsForNpcType(randomNpc.Type, accessPoint);

                if (randomNpc != null && compatibleDestinations != null && compatibleDestinations.Count > 0)
                {
                    accessPoint.SpawnNpc(randomNpc.prefab, compatibleDestinations);
                    _availableAccessPoints.Remove(accessPoint);
                    randomNpc.Count++;
                }
                else
                {
                    Debug.LogError("Failed to spawn an NPC");
                }
            }
            else
            {
                Debug.LogError("An NPC is missing its NpcType component");
            }
        }
        else
        {
            Debug.Log("All NPCs types have been maxed out");
        }
    }