Пример #1
0
 private void Awake()
 {
     navMeshAgentController = GetComponent<NavMeshAgentController>();
     renderer = GetComponent<Renderer>();
     color = availableColors[Random.Range(0, availableColors.Length)];
     renderer.material.color = color;
 }
    /// <summary>
    /// Try to create an agent on the NavMesh.
    /// </summary>
    public void Create()
    {
        //If the agent and the NavMesh have different agent IDs, don't assign it.
        if (agentType != agentTypeNavMeshID)
        {
            UnityEngine.Debug.LogWarning("The agent ID differs from the NavMesh");
            return;
        }
        //Instantiate the prefab and try to place it on the NavMesh.
        enemies.Add(Instantiate(enemyPrefab, centerNavMesh, Quaternion.identity));
        List <GameObject> notActivated = new List <GameObject>();

        //For each enemy created, move it on the NavMesh.
        foreach (GameObject o in enemies)
        {
            NavMeshAgentController a = o.GetComponent <NavMeshAgentController>();
            if (a.Move())
            {
                a.GetComponent <RandomWalk>().Activate();
                noNavMeshCount = 0;
            }
            else
            {
                notActivated.Add(a.gameObject);
                noNavMeshCount++;
            }
        }

        //Destroy any objects that were not properly added to the NavMesh.
        foreach (GameObject o in notActivated)
        {
            Destroy(o);
            enemies.Remove(o);
        }
    }
Пример #3
0
 private void Awake()
 {
     navMeshAgentController = GetComponent <NavMeshAgentController>();
     renderer = GetComponent <Renderer>();
     color    = availableColors[Random.Range(0, availableColors.Length)];
     renderer.material.color = color;
 }
Пример #4
0
    /// <summary>
    /// Try to create an agent on the navMesh
    /// </summary>
    public void Create()
    {
        //If the agent and the navMesh have two area type different
        if (agentType != agentTypeNavMeshID)
        {
            Debug.LogWarning("The agent ID differs from the NavMesh");
            return;
        }
        //Create a gameobject to try to set it on the NavMesh
        enemies.Add(Instantiate(enemyPrefab, centerNavMesh, Quaternion.identity));
        List <GameObject> notActivated = new List <GameObject>();

        //For each enemy created move it on the navMesh
        foreach (GameObject o in enemies)
        {
            NavMeshAgentController a = o.GetComponent <NavMeshAgentController>();
            if (a.Move())
            {
                a.GetComponent <RandomWalk>().Activate();
                noNavMeshCount = 0;
            }
            else
            {
                notActivated.Add(a.gameObject);
                noNavMeshCount++;
            }
        }

        //Destroy the objects missing the NavMesh
        foreach (GameObject o in notActivated)
        {
            Destroy(o);
            enemies.Remove(o);
        }
    }
Пример #5
0
    private void Awake()
    {
        navMeshAgent = GetComponent <NavMeshAgentController>();

        /* Set States */
        states = new Dictionary <EnemySatate, EnemyStateBase>();
        states.Add(EnemySatate.Patrol, new PatrolState(this));
        states.Add(EnemySatate.Alert, new AlertState(this));
        states.Add(EnemySatate.Chase, new ChaseState(this));
        states.Add(EnemySatate.Fire, new FireState(this));
        currentState = states[EnemySatate.Patrol];

        orginalPosition = transform.position;

        player = GameObject.FindGameObjectWithTag("Player").transform;

        if (Fire)
        {
            ammo = GetComponent <AmmoInventory>();
        }
    }
Пример #6
0
 private void Awake()
 {
     navMeshAgentController = GetComponent<NavMeshAgentController>();
 }
Пример #7
0
 private void Awake()
 {
     navMeshAgentController = GetComponent<NavMeshAgentController>();
     attributePool = GetComponentInChildren<AttributePool>();
 }
Пример #8
0
 private void Awake()
 {
     navMeshAgentController = GetComponent <NavMeshAgentController>();
     attributePool          = GetComponentInChildren <AttributePool>();
 }