// spwaner function
 IEnumerator Start()
 {
     agents = new List <GameObject> ();
     while (true)
     {
         Transform randomLocation = SpwanLocations [Random.Range(0, SpwanLocations.Count)];
         var       agent          = GameObject.Instantiate(agentPrefab, randomLocation.position, randomLocation.rotation, transform) as GameObject;
         UnityEngine.AI.NavMeshAgent agentNavMesh = agent.GetComponent <UnityEngine.AI.NavMeshAgent> ();
         var value = 100 * Random.value;
         if (value < GoToStationPrecentage)               //spwan to BRT
         {
             agentNavMesh.SetDestination(ThisStateGoal.position);
             agentNavMesh.GetComponent <Renderer> ().material.color = Color.yellow;
             agent.tag = "AgentBRT";
         }
         else                 //or to random targets
         {
             Transform randomTarget = SpwanLocations [Random.Range(0, SpwanLocations.Count)];
             agentNavMesh.SetDestination(randomTarget.position);
             agentNavMesh.GetComponent <Renderer> ().material.color = Color.white;
             agent.tag = "Untagged";
         }
         agents.Add(agent);
         yield return(new WaitForSeconds(delaySpwan));
     }
 }
Example #2
0
 void Start()
 {
     agent             = GetComponent <UnityEngine.AI.NavMeshAgent> ();
     agent.autoBraking = true;
     anim = agent.GetComponent <Animator> ();
     GotoNextPoint();
 }
 void Awake()
 {
     player       = GameObject.FindGameObjectWithTag("Player").transform;
     playerObject = GameObject.FindGameObjectWithTag("Player");
     agent        = GetComponent <UnityEngine.AI.NavMeshAgent>();
     bc           = agent.GetComponent <BoxCollider2D>();
     enemyHealth  = GetComponent <EnemyHealth>();
     playerHealth = playerObject.GetComponent <PlayerHealth>();
 }
Example #4
0
    void spwanerMethod()
    {
        // creating the agent //
        Transform randomSpwanLocation = SpwanLocations [Random.Range(0, SpwanLocations.Count)];

        agent = GameObject.Instantiate
                    (agentPrefab, randomSpwanLocation.position, randomSpwanLocation.rotation, transform) as GameObject;     //make the agent
        UnityEngine.AI.NavMeshAgent agentNavMesh = agent.GetComponent <UnityEngine.AI.NavMeshAgent> ();


        // Target alocation //

        var value = 100 * Random.value;

        if (value < 30)           //spwan

        {
            Transform randomTarget = TargetLocations [Random.Range(0, TargetLocations.Count / 3)];
            agentNavMesh.SetDestination(randomTarget.position);
            agentNavMesh.GetComponent <Renderer> ().material.color = Color.red;
            agent.GetComponent <AgentsController> ()._target_id    = randomTarget.gameObject.GetComponent <TargetController> ().GetID();
            agent.tag = "Rich";
        }
        else if (value > 30 && value < 60)             //or to random targets

        {
            Transform randomTarget = TargetLocations [Random.Range(TargetLocations.Count / 3, ((TargetLocations.Count * 60) / 100))];
            agentNavMesh.SetDestination(randomTarget.position);
            agentNavMesh.GetComponent <Renderer> ().material.color = Color.yellow;
            agent.GetComponent <AgentsController> ()._target_id    = randomTarget.gameObject.GetComponent <TargetController> ().GetID();
            agent.tag = "Medium";
        }
        else if (value > 60 && value < 100)             //or to random targets

        {
            Transform randomTarget = TargetLocations [Random.Range(((TargetLocations.Count * 60) / 100), TargetLocations.Count)];
            agentNavMesh.SetDestination(randomTarget.position);
            agentNavMesh.GetComponent <Renderer> ().material.color = Color.green;
            agent.GetComponent <AgentsController> ()._target_id    = randomTarget.gameObject.GetComponent <TargetController> ().GetID();
            agent.tag = "Poor";
        }
    }
Example #5
0
 override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
 {
     //Llamamos a la malla de navegación
     agent = animator.GetComponent <UnityEngine.AI.NavMeshAgent>();
     //Encuentra todos los gameObjects que posean en tag Goal creado previamente en el inspector de Unity
     goal = GameObject.FindGameObjectsWithTag("Goal");
     //El destino del NavMeshAgent debe ser el primer valor de la matriz
     agent.destination = goal[0].transform.position;
     //El color de este agente en este estado es azul
     agent.GetComponent <Renderer>().material.color = Color.blue;
 }
    IEnumerator InStation(UnityEngine.AI.NavMeshAgent agent)
    {
        Transform randomTarget = SpwanLocations [Random.Range(1, SpwanLocations.Count)];

        agent.SetDestination(randomTarget.position);
        agent.Stop();
        yield return(new WaitForSeconds(LeaveStationAfterTime));

        agent.Resume();
        agent.GetComponent <Renderer> ().material.color = Color.red;
    }
Example #7
0
 void Start()
 {
     agenttf = agent.GetComponent <Transform>();
 }