public void SpawnObjects()
    {
        for (int i = 0; i < SpawnCount; i++)
        {
            // Spawn the object. If we have an object in the pool, use that instead. Else, instantiate.
            GameObject obj;
            if (pooledObjects.Count > 0)
            {
                // get the last pooled object
                obj = pooledObjects[0];
                pooledObjects.RemoveAt(0);
                obj.SetActive(true);
                InitializeSpawnObject(obj);
                currentSpawnedObjects.Add(obj);
            }
            else
            {
                obj = Instantiate(ObjectToSpawn);
                InitializeSpawnObject(obj);
                currentSpawnedObjects.Add(obj);
            }


            // Randomize position
            obj.transform.position = SpawnPosition;

            EVT_OnObjectSpawned.Invoke();
        }
    }
示例#2
0
        private GameObject ServerSpawnObject(GameObject entityPrefab, Vector3 worldPosition, PortalSpawnInfo settings)
        {
            // Spawn object at landing zone, (sprite will move back up to worldPosition for animation).
            GameObject entity = Spawn.ServerPrefab(entityPrefab, worldPosition).GameObject;

            OnObjectSpawned?.Invoke(entity);
            UpdateManager.Instance.StartCoroutine(ServerRunObjectSequence(entity, settings));

            return(entity);
        }
示例#3
0
    private void Spawn()
    {
        Vector3    ranomPos = new Vector3(Random.Range(-sizeSpawnZone.x, sizeSpawnZone.x), 0, Random.Range(-sizeSpawnZone.z, sizeSpawnZone.z));
        GameObject go       = Instantiate(prefab, ranomPos, Quaternion.identity);

        if (lifeTime != -1)
        {
            Destroy(go, lifeTime);
        }
        OnObjectSpawned?.Invoke(go);
    }
示例#4
0
    private void InputInteraction_OnSelectObjectInteraction(Vector3 position)
    {
        var spawnedObject = SpawnAt(position);

        OnObjectSpawned?.Invoke(spawnedObject);
    }
示例#5
0
 public void Spawn()
 {
     prefab.transform.position = new Vector2(UnityEngine.Random.Range(-border, border),
                                             UnityEngine.Random.Range(-border, border));
     OnObjectSpawned.Invoke(prefab.transform);
 }