/// <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); } }
/// <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); } }
protected bool SetNextCheckPoint(int index) { var destination = GameObject.Find("CheckPoint" + index); if (destination == null) { return(false); } playerController.Destination = destination; playerController.Move(); _checkPointIndex = index; return(true); }