예제 #1
0
    protected virtual void NewDestination()
    {
        Vector3 new_dest = new Vector3(Random.Range(-125f, 125f), 0f, Random.Range(-125f, -75f));

        int j = -NumMembers / 2;

        for (int i = 0; i < members.Length; i++)
        {
            if (members[i] != null)
            {
                members[i].Destination          = new Vector3(new_dest.x + j * 7.5f, 0f, new_dest.z - Mathf.Abs(j) * 5f);
                members[i].destination.rotation = Quaternion.identity;
                HelicopterEnemy h = members[i] as HelicopterEnemy;
                if (h != null)
                {
                    h.fired = false;
                }
                j++;
            }
        }
    }
예제 #2
0
    protected override void _Update()
    {
        base._Update();

        bool finished = true;

        foreach (Enemy e in this)
        {
            HelicopterEnemy h = e as HelicopterEnemy;
            if (h != null && !h.fired)
            {
                finished = false;
                break;
            }
        }

        if (finished)
        {
            NewDestination();
        }
    }
예제 #3
0
    private void PlaceEnemies()
    {
        PlayspaceManager pm = PlayspaceManager.Instance;

        string placementName;

        Vector3 agent1Size  = Footprint.Measure(agentPrefab1);
        float   agent1Width = Mathf.Max(agent1Size.x, agent1Size.z);

        for (int i = 0; i < 3; i++)
        {
            TaskManager.Instance.Schedule(
                () =>
            {
                Vector3 position;
                if (pm.TryPlaceOnPlatform(out position, 0.25f, 1.5f, 1.5f * agent1Width))
                {
                    return(() =>
                    {
                        NavMeshHit hit;
                        if (NavMesh.SamplePosition(position, out hit, 2, NavMesh.AllAreas))
                        {
                            position = hit.position;
                        }
                        GameObject agent = Instantiate(agentPrefab1, position, Quaternion.identity);
                        SetTarget(agent, playerHelicopter);
                    });
                }
                return(null);
            });
        }

        Vector3 agent2Size  = Footprint.Measure(agentPrefab2);
        float   agent2Width = Mathf.Max(agent2Size.x, agent2Size.z);

        for (int i = 0; i < 2; i++)
        {
            TaskManager.Instance.Schedule(
                () =>
            {
                Vector3 position;
                Quaternion rotation;
                if (pm.TryPlaceOnPlatform(out position, 0.25f, 1.5f, 1.5f * agent2Width))
                {
                    return(() =>
                    {
                        NavMeshHit hit;
                        if (NavMesh.SamplePosition(position, out hit, 2, NavMesh.AllAreas))
                        {
                            position = hit.position;
                        }
                        GameObject agent = Instantiate(agentPrefab2, position, Quaternion.identity);
                        SetTarget(agent, playerHelicopter);
                    });
                }
                else if (pm.TryPlaceOnFloor(out placementName, out position, out rotation, agent2Size))
                {
                    return(() =>
                    {
                        NavMeshHit hit;
                        if (NavMesh.SamplePosition(position, out hit, 2, NavMesh.AllAreas))
                        {
                            position = hit.position;
                        }
                        GameObject agent = Instantiate(agentPrefab2, position, rotation);
                        SetTarget(agent, playerHelicopter);
                    });
                }
                return(null);
            });
        }

        Vector3 agent3Size  = Footprint.Measure(agentPrefab3);
        float   agent3Width = Mathf.Max(agent3Size.x, agent3Size.z);

        for (int i = 0; i < 1; i++)
        {
            TaskManager.Instance.Schedule(
                () =>
            {
                Vector3 position;
                Quaternion rotation;
                if (pm.TryPlaceOnPlatform(out position, 0.25f, 1.5f, 1.5f * agent3Width))
                {
                    return(() =>
                    {
                        NavMeshHit hit;
                        if (NavMesh.SamplePosition(position, out hit, 2, NavMesh.AllAreas))
                        {
                            position = hit.position;
                        }
                        GameObject agent = Instantiate(agentPrefab3, position, Quaternion.identity);
                        SetTarget(agent, playerHelicopter);
                    });
                }
                else if (pm.TryPlaceOnFloor(out placementName, out position, out rotation, agent3Size))
                {
                    return(() =>
                    {
                        NavMeshHit hit;
                        if (NavMesh.SamplePosition(position, out hit, 2, NavMesh.AllAreas))
                        {
                            position = hit.position;
                        }
                        GameObject agent = Instantiate(agentPrefab3, position, rotation);
                        SetTarget(agent, playerHelicopter);
                    });
                }
                return(null);
            });
        }

        Vector3 enemyHelicopter1Size = Footprint.Measure(enemyHelicopterPrefab1.gameObject);

        for (int i = 0; i < 1; i++)
        {
            TaskManager.Instance.Schedule(
                () =>
            {
                Vector3 position;
                Quaternion rotation;
                List <PlayspaceManager.Rule> rules = new List <PlayspaceManager.Rule>()
                {
                    PlayspaceManager.Rule.Nearby(m_besiegedBuildingPosition, 0f, 0.25f)
                };
                if (pm.TryPlaceInAir(out position, out rotation, enemyHelicopter1Size, rules))
                {
                    return(() =>
                    {
                        HelicopterEnemy enemyHelicopter = Instantiate(enemyHelicopterPrefab1, position, rotation);
                        SetTarget(enemyHelicopter.gameObject, playerHelicopter);
                    });
                }
                return(() => { Debug.Log("Failed to place enemy helicopter"); });
            });
        }
    }