Exemplo n.º 1
0
    protected virtual GameObject SpawnInternal(Spawnee spawnee)
    {
        (GameObject, Spawned)result = spawnee.SpawnNewInstance(this.transform, this);
        if (result.Item1 != null)
        {
            SpawnedNavMeshAgentNavigator navigator = result.Item1.AddComponent <SpawnedNavMeshAgentNavigator>();
            if (navigator != null)
            {
                try {
                    navigator.EnsureNavMeshAgent();
                    navigator.SetAreaCostOverrides(this.areaCostOverrides);

                    List <Spawner> otherSpawners = this.GetAllOtherSpawners();
                    if (otherSpawners == null || otherSpawners.Count == 0)
                    {
                        throw new UnityException("Unable to find other Spawners to use as destination");
                    }

                    Spawner otherSpawner = otherSpawners[UnityEngine.Random.Range(0, otherSpawners.Count)];

                    navigator.SetDestination(otherSpawner.transform);
                    return(result.Item1);
                } catch (System.Exception e) {
                    Debug.LogError(e, this);
                }
            }

            Destroy(result.Item1);
        }

        return(null);
    }
Exemplo n.º 2
0
    protected override GameObject SpawnInternal(Spawnee spawnee)
    {
        (GameObject, Spawned)result = spawnee.SpawnNewInstance(this.transform, this);
        if (result.Item1 != null)
        {
            SpawnedVelocityNavigator navigator = result.Item1.AddComponent <SpawnedVelocityNavigator>();
            if (navigator != null)
            {
                navigator.velocity = Utility.RandomWithin(spawnee.speed);
                return(result.Item1);
            }

            Destroy(result.Item1);
        }

        return(null);
    }