예제 #1
0
    //private void SpawnMainPed(Transform spawnT = null)
    //{
    //    Vector3 tempV = Vector3.zero;
    //    if (spawnT != null)
    //        tempV = spawnT.position;

    //    mainPedGO = Instantiate(pedPrefab, tempV, Quaternion.identity, this.transform);
    //    Instantiate(pedestrians[(int)Random.Range(0, pedestrians.Count)], mainPedGO.transform);
    //    mainPedGO.name = "MainPedestrian";

    //    mainPedC = mainPedGO.GetComponent<PedestrianComponent>();
    //    if (mainPedC != null)
    //        mainPedC.InitPed(true);
    //}

    public PedestrianComponent SpawnMainPed(Transform spawnT = null)
    {
        if (mainPedGO != null)
        {
            Destroy(mainPedGO);
        }

        Vector3 tempV = Vector3.zero;

        if (spawnT != null)
        {
            tempV = spawnT.position;
        }

        mainPedGO = Instantiate(pedPrefab, tempV, Quaternion.identity, this.transform);
        Instantiate(pedestrians[(int)Random.Range(0, pedestrians.Count)], mainPedGO.transform);
        mainPedGO.name = "MainPedestrian";

        mainPedC = mainPedGO.GetComponent <PedestrianComponent>();
        if (mainPedC != null)
        {
            mainPedC.InitPed(true);
        }

        return(mainPedC);
    }
    public void SpawnPedestrian(MapPedestrianSegmentBuilder seg)
    {
        if (pedPool.Count == 0)
        {
            return;
        }

        GameObject ped = pedPool[0];

        ped.transform.SetParent(seg.transform);
        pedPool.RemoveAt(0);
        pedActive.Add(ped);
        ped.SetActive(true);
        PedestrianComponent pedC = ped.GetComponent <PedestrianComponent>();

        if (pedC != null)
        {
            pedC.InitPed(seg.segment.targetWorldPositions);
        }
    }
예제 #3
0
 private IEnumerator SpawnNPCPeds()
 {
     npcGOs.Clear();
     for (int i = 0; i < pedSpawners.Count; i++)
     {
         for (int j = 0; j < perPedSpawnerCount; j++)
         {
             GameObject ped = Instantiate(pedPrefab, pedSpawners[i].GetPositionBetweenTargets(), Quaternion.identity, pedSpawners[i].transform);
             npcGOs.Add(ped);
             Instantiate(pedestrians[(int)Random.Range(0, pedestrians.Count)], ped.transform);
             PedestrianComponent pedC = ped.GetComponent <PedestrianComponent>();
             if (pedC != null)
             {
                 pedC.InitPed();
             }
             yield return(new WaitForEndOfFrame());
         }
         yield return(new WaitForEndOfFrame());
     }
 }
 public void DespawnPedestrianApi(PedestrianComponent ped)
 {
     Destroy(ped.gameObject);
 }