예제 #1
0
        // spawn randowm object in type
        public PooledObject Spawn(eSpawn type, Vector3 initPos = default(Vector3))
        {
            PooledObject[] objPrefab = null;
            Transform[]    posPrefab = null;
            switch (type)
            {
            case eSpawn.Player:
                objPrefab = objPrefabPlayer;
                posPrefab = spots;
                break;

            case eSpawn.NonPlayer:
                objPrefab = objPrefabNPC;
                posPrefab = spots;
                break;
            }
            int index = Random.Range(0, posPrefab.Length);

            if (objPrefab != null && posPrefab != null)
            {
                const int tryCnt = 5;
                if (initPos == default(Vector3))
                {
                    for (int i = 0; i < tryCnt; ++i)
                    {
                        if (Facade_NavMesh.RandomRangePoint(posPrefab[index].position, 0, 10f, out initPos))
                        {
                            break;
                        }
                    }
                }

                // fails to found the position
                if (initPos == default(Vector3))
                {
                    return(null);
                }

                var objSpawn = SpawnObject(objPrefab[Random.Range(0, objPrefab.Length)], initPos);
                // save for searching in AI
                ObjectProperty property = objSpawn as ObjectProperty;
                if (null != property)
                {
                    All.Add(property);
                }
                return(objSpawn);
            }

            return(null);
        }
예제 #2
0
 public Transform FindRandomSpawnSpot(eSpawn type)
 {
     return(spots[Random.Range(0, spots.Length)]);
 }