private void Awake()//Ran once the program starts { instance = this; GameObject player2 = GameObject.Find("Lumberjack2"); player2.SetActive(false); GameObject player3 = GameObject.Find("Lumberjack3"); player3.SetActive(false); fNodeDiameter = fNodeRadius * 2; //Double the radius to get diameter iGridSizeX = Mathf.RoundToInt(vGridWorldSize.x / fNodeDiameter); //Divide the grids world co-ordinates by the diameter to get the size of the graph in array units. iGridSizeY = Mathf.RoundToInt(vGridWorldSize.y / fNodeDiameter); //Divide the grids world co-ordinates by the diameter to get the size of the graph in array units. CreateGrid(); //Draw the grid if (scenario == Scenario.Known && algorithm == Algorithm.AStar) { print("Scenario : " + scenario + ", Algorithm = " + algorithm); PathfindingA PAscript = this.gameObject.AddComponent(typeof(PathfindingA)) as PathfindingA; GameObject player = GameObject.Find("Agent"); Unit unitScript = player.gameObject.AddComponent(typeof(Unit)) as Unit; unitScript.enabled = true; PAscript.enabled = true; } else if (scenario == Scenario.Known && algorithm == Algorithm.Dijkstra) { print("Scenario : " + scenario + ", Algorithm = " + algorithm); Dijkstra DIJscript = this.gameObject.AddComponent(typeof(Dijkstra)) as Dijkstra; GameObject player = GameObject.Find("Agent"); UnitDijkstra unitDijkstraScript = player.gameObject.AddComponent(typeof(UnitDijkstra)) as UnitDijkstra; unitDijkstraScript.enabled = true; DIJscript.enabled = true; } else if (scenario == Scenario.Unknown && searchMode == SearchMode.CellByCell) { print("Scenario : " + scenario + ", Search Mode : " + searchMode + " , Algorithm = " + algorithm); GameObject player = GameObject.Find("Agent"); UnitSearchUnkCell UnitSearchscript = player.gameObject.AddComponent(typeof(UnitSearchUnkCell)) as UnitSearchUnkCell; UnitSearchscript.enabled = true; } else if (scenario == Scenario.Unknown && searchMode == SearchMode.Randomly) { print("Scenario : " + scenario + ", Search Mode : " + searchMode + " , Algorithm = " + algorithm); GameObject player = GameObject.Find("Agent"); UnitRandom UnitRandomscript = player.gameObject.AddComponent(typeof(UnitRandom)) as UnitRandom; UnitRandomscript.enabled = true; } else if (scenario == Scenario.ThreeAgents) { player2.SetActive(true); player3.SetActive(true); print("Scenario : " + scenario + ", Algorithm = " + algorithm); ThreeAgents CompThreeAgents = this.gameObject.AddComponent(typeof(ThreeAgents)) as ThreeAgents; CompThreeAgents.enabled = true; } }
void Start() { playerMeet = new List <GameObject>(); nbTrees = GridWorld.instance.nbTrees; UnitRandom UnitRandomscript2 = player2.gameObject.AddComponent(typeof(UnitRandom)) as UnitRandom; UnitRandomscript2.enabled = true; LostForest CompLostForest2 = player2.gameObject.AddComponent(typeof(LostForest)) as LostForest; CompLostForest2.enabled = true; UnitRandom UnitRandomscript3 = player3.gameObject.AddComponent(typeof(UnitRandom)) as UnitRandom; UnitRandomscript3.enabled = true; LostForest CompLostForest3 = player3.gameObject.AddComponent(typeof(LostForest)) as LostForest; CompLostForest3.enabled = true; UnitSearchUnkCell UnitSearchscript = player.gameObject.AddComponent(typeof(UnitSearchUnkCell)) as UnitSearchUnkCell; UnitSearchscript.enabled = true; LostForest CompLostForest = player.gameObject.AddComponent(typeof(LostForest)) as LostForest; CompLostForest.enabled = true; Vector3 positionSawmill = new Vector3(Random.Range(-10.0f, 10.0f), 0, Random.Range(-10.0f, 10.0f)); if (checkIfPosEmpty(positionSawmill)) { GameObject sawmill = GameObject.Find("Sawmill"); sawmill.transform.position = positionSawmill; } for (int i = 0; i < nbTrees; i++) { Vector3 positionTree = new Vector3(Random.Range(-10.0f, 10.0f), 0, Random.Range(-10.0f, 10.0f)); if (checkIfPosEmpty(positionTree)) { GameObject trees = GameObject.Find("Tree"); Instantiate(trees, positionTree, Quaternion.identity); } } }