/// <summary> /// Place a Unit using a selectedType at the mousePosition inside a valid UnitSpawnArea /// </summary> /// <param name="selectedType"></param> public void PlaceUnitOfSelectedType(GameManager.ClassTypes selectedType) { if (currentNumOfUnits < maxNumOfUnits) { //Raycast to point on screen and check if the unit can spawn here RaycastHit hit; if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, 100) && hit.collider.gameObject.tag == "UnitSpawnArea") { //Check the current class selection and Instantiate that Unit at hit.point switch (selectedType) { case GameManager.ClassTypes.Warrior: AddToUnitList(Instantiate(prefabWarriorUnit, hit.point, Quaternion.identity)); break; case GameManager.ClassTypes.Ranger: AddToUnitList(Instantiate(prefabRangerUnit, hit.point, Quaternion.identity)); break; case GameManager.ClassTypes.Rogue: AddToUnitList(Instantiate(prefabRogueUnit, hit.point, Quaternion.identity)); break; case GameManager.ClassTypes.Healer: AddToUnitList(Instantiate(prefabHealerUnit, hit.point, Quaternion.identity)); break; } } } }
/// <summary> /// Place a Building at the Player Base using a selectedType /// </summary> /// <param name="selectedType"></param> public void PlaceBuildingOfSelectedType(GameManager.ClassTypes selectedType) { if (currentNumOfBuildings < maxNumOfBuildings) { //Raycast to point on screen and check if the building can spawn here RaycastHit hit; if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, 100) && hit.collider.gameObject.tag == "Base") { //Check the current class selection and Instantiate that Building at hit.point switch (selectedType) { case GameManager.ClassTypes.Warrior: AddBuildingToBase(Instantiate(prefabWarriorBuilding, hit.point, Quaternion.identity)); break; case GameManager.ClassTypes.Ranger: AddBuildingToBase(Instantiate(prefabRangerBuilding, hit.point, Quaternion.identity)); break; case GameManager.ClassTypes.Rogue: AddBuildingToBase(Instantiate(prefabRogueBuilding, hit.point, Quaternion.identity)); break; case GameManager.ClassTypes.Healer: AddBuildingToBase(Instantiate(prefabHealerBuilding, hit.point, Quaternion.identity)); break; } currentNumOfBuildings++; } } else { Debug.Log("Maximum Num Of Buildings Reached"); } }
/// <summary> /// If this is the Enemy UnitManager, try to place a unit of the selectedType at either of the two given Spawn Areas /// </summary> /// <param name="selectedType"></param> public void PlaceUnitOfSelectedTypeRandomly(GameManager.ClassTypes selectedType) { if (this.baseManager.HasSelectedType(selectedType) && currentNumOfUnits < maxNumOfUnits) { GameObject randomSpawnArea = GetRandomSpawnArea(); //Check the current class selection and Instantiate that Unit at hit.point switch (selectedType) { case GameManager.ClassTypes.Warrior: AddToUnitList(Instantiate(prefabWarriorUnit, randomSpawnArea.transform.position, Quaternion.identity)); break; case GameManager.ClassTypes.Ranger: AddToUnitList(Instantiate(prefabRangerUnit, randomSpawnArea.transform.position, Quaternion.identity)); break; case GameManager.ClassTypes.Rogue: AddToUnitList(Instantiate(prefabRogueUnit, randomSpawnArea.transform.position, Quaternion.identity)); break; case GameManager.ClassTypes.Healer: AddToUnitList(Instantiate(prefabHealerUnit, randomSpawnArea.transform.position, Quaternion.identity)); break; } } }
/// <summary> /// Check this base for a specified ClassType. /// </summary> /// <param name="_selectedType"></param> /// <returns></returns> public virtual bool HasSelectedType(GameManager.ClassTypes _selectedType) { foreach (GameObject building in this.Buildings) { if (building.GetComponent <BuildingController>().type == _selectedType) { return(true); } } return(false); }