public void Farm_Placer_Controller() { //Find the posision of the mouse mouse_pos = mouse_position_script.Get_Mouse_Pos(); //If you click and you are not selecting an area //If you not clicking a button if (Input.GetMouseButtonUp(0) && selecting_area == false && ui_manager_script.Get_Button_Pressed() == false) { //Make the click position equal the mouse position //Change bool to say you are selecting an area click_pos = mouse_pos; selecting_area = true; } //If the farms area is smaller than 100 in area //If you click and you are not selecting an area //If you are not clicking a button //If it is not colliding with anything else if (Input.GetMouseButtonUp(0) && ui_manager_script.Get_Button_Pressed() == false && selecting_area == true && is_colliding == false && (Mathf.Abs(click_pos[0] - mouse_pos[0]) + 1) * (Mathf.Abs(click_pos[2] - mouse_pos[2]) + 1) <= 100 && (Mathf.Abs(click_pos[0] - mouse_pos[0]) + 1) * (Mathf.Abs(click_pos[2] - mouse_pos[2]) + 1) >= 10) { //Creates the farm object //Resizes it to the correct dimentions perm_farm_placer = Instantiate(perm_farm_object, new Vector3((click_pos[0] + mouse_pos[0]) / 2, 0, (click_pos[2] + mouse_pos[2]) / 2), rot_zero); perm_farm_placer.transform.localScale = new Vector3(Mathf.Abs(click_pos[0] - mouse_pos[0]) + 1, 0.1f, Mathf.Abs(click_pos[2] - mouse_pos[2]) + 1); //Change bool to say you are not selecting an area selecting_area = false; //Adds a building to the building amounts list data_manager_script.Change_Building(5, 1); } //If you right click and you are selecting an area //Change bool to say you are not selecting an area if (Input.GetMouseButtonUp(1) && selecting_area == true) { selecting_area = false; } //Destroy old selector and place down new on inbetween the two corner points //Change the scale so that the selector goes between both corners. if (selecting_area == true) { Destroy(temp_farm_placer); temp_farm_placer = Instantiate(temp_farm_object, new Vector3((click_pos[0] + mouse_pos[0]) / 2, 0, (click_pos[2] + mouse_pos[2]) / 2), rot_zero); temp_farm_placer.transform.localScale = new Vector3(Mathf.Abs(click_pos[0] - mouse_pos[0]) + 1, 0.1f, Mathf.Abs(click_pos[2] - mouse_pos[2]) + 1); } //If you are not selecting an area destory the previous selector and place down a new selector. else { Destroy(temp_farm_placer); temp_farm_placer = Instantiate(temp_farm_object, new Vector3(mouse_pos[0], 0, mouse_pos[2]), rot_zero); } //Resets variable every time the script is run is_colliding = false; }
public void Road_Builder_Controller() { //Calls function Get_Mouse_Pos from another script and stores output in mouse_pos mouse_pos = mouse_position_script.Get_Mouse_Pos(); //Destroys and recreates temp_road with gameobject temp_road_parent in it Destroy(temp_road); temp_road = Instantiate(temp_road_parent); //if variable is false create a gameobject as a child of temp_road if (drawing_road == false) { Instantiate(temp_road_object, mouse_pos, rot_zero, temp_road.transform); } //If you are clicking the left mouse button //If you are not drawing a road //If your not clicking a button if (Input.GetMouseButtonUp(0) && drawing_road == false && ui_manager_script.Get_Button_Pressed() == false) { //Make the click position equal the mouse position //Change bool to say you are selecting an area drawing_road = true; click_pos = mouse_pos; } //If you are clicking the left mouse button //If you are not drawing a road //If you are not colliding with anything //If your not clicking a button else if (Input.GetMouseButtonUp(0) && ui_manager_script.Get_Button_Pressed() == false && drawing_road == true && is_colliding == false) { //Stop drawing road //Run the method drawing_road = false; Perm_Road_Placer(); } //If variable is true run procdure else if (drawing_road == true) { Temp_Road_Placer(); } //right clicking stops the building of a road if (Input.GetMouseButtonUp(1) && drawing_road == true) { drawing_road = false; } //Every time the script is run it resets the bool to false is_colliding = false; }
public void Resource_Collection_Controller() { //Find the posision of the mouse mouse_pos = mouse_position_script.Get_Mouse_Pos(); //If you left click and you are not collecting a resource //If you are not clicking a button if (Input.GetMouseButtonUp(0) && resource_collection == false && ui_manager_script.Get_Button_Pressed() == false) { //Make the click position equal the mouse position //Change bool to say you are selecting an area click_pos = mouse_pos; resource_collection = true; } //If you left click and you are collecting a resource else if (Input.GetMouseButtonUp(0) && resource_collection == true) { //Change bool to say you are not collecting a resource resource_collection = false; } //If you right click and you are collecting a resource if (Input.GetMouseButtonUp(1) && resource_collection == true) { //Change bool to say you are not collecting a resource resource_collection = false; } //If you are collecting a resource if (resource_collection == true) { //Destroy old collector and places down a new one inbetween the two points //Change the scale so that the selector fits between both corners. Destroy(resource_collector_placer); resource_collector_placer = Instantiate(current_resource_collector, new Vector3((click_pos[0] + mouse_pos[0]) / 2, 0, (click_pos[2] + mouse_pos[2]) / 2), rot_zero); resource_collector_placer.transform.localScale = new Vector3(Mathf.Abs(click_pos[0] - mouse_pos[0]) + 1, 0.1f, Mathf.Abs(click_pos[2] - mouse_pos[2]) + 1); } //If you are not collecting a resource else { //Destory the previous collector and place down a new one Destroy(resource_collector_placer); resource_collector_placer = Instantiate(current_resource_collector, new Vector3(mouse_pos[0], 0, mouse_pos[2]), rot_zero); } }
public void Bulldozer_Controller() { //Find the posision of the mouse mouse_pos = mouse_position_script.Get_Mouse_Pos(); //If you click and you are not selecting an area //Make the click position equal the mouse position //Change bool to say you are selecting an area if (Input.GetMouseButtonUp(0) && bulldozing == false && ui_manager_script.Get_Button_Pressed() == false) { click_pos = mouse_pos; bulldozing = true; } //If you click and you are selecting an area //Change bool to say you are not selecting an area else if (Input.GetMouseButtonUp(0) && bulldozing == true) { bulldozing = false; } //If you right click and you are selecting an area //Change bool to say you are not selecting an area if (Input.GetMouseButtonUp(1) && bulldozing == true) { bulldozing = false; } //Destroy old selector and place down new on inbetween the two corner points //Change the scale so that the selector goes between both corners. if (bulldozing == true) { Destroy(bulldozer_placer); bulldozer_placer = Instantiate(bulldozer_object, new Vector3((click_pos[0] + mouse_pos[0]) / 2, 0, (click_pos[2] + mouse_pos[2]) / 2), rot_zero); bulldozer_placer.transform.localScale = new Vector3(Mathf.Abs(click_pos[0] - mouse_pos[0]) + 1, 0.1f, Mathf.Abs(click_pos[2] - mouse_pos[2]) + 1); } //If you are not selecting an area destory the previous selector and place down a new selector. else { Destroy(bulldozer_placer); bulldozer_placer = Instantiate(bulldozer_object, new Vector3(mouse_pos[0], 0, mouse_pos[2]), rot_zero); } }
public void Building_Placer_Controller() { //Calls function Get_Mouse_Pos and returns vector3 mouse_pos = mouse_position_script.Get_Mouse_Pos(); //Makes sure that the object isnt inside another object //Checks to see if you have enough resources in the inventory //Makes sure you arent clicking a button if (Input.GetMouseButtonUp(0) && ui_manager_script.Get_Button_Pressed() == false && is_colliding == false && gold_cost <= data_manager_script.Check_Resources(0) && wood_cost <= data_manager_script.Check_Resources(1) && stone_cost <= data_manager_script.Check_Resources(2) && iron_cost <= data_manager_script.Check_Resources(3)) { //Places a building at mouse Instantiate(perm_building, mouse_pos, rot_building); //Takes away the correct amount of resoucrces for the building data_manager_script.Change_Resources(1, -gold_cost); data_manager_script.Change_Resources(1, -wood_cost); data_manager_script.Change_Resources(2, -stone_cost); data_manager_script.Change_Resources(1, -iron_cost); //Changes the amount of that type of building in the list by 1 data_manager_script.Change_Building(current_building_key, 1); } else { //Destroys the old tempereary building and creates new one at the mouse Destroy(temp_building_object); temp_building_object = Instantiate(temp_building, mouse_pos, rot_building); } //If R is pressed call the method if (Input.GetKeyDown("r") == true) { Building_Rotation(); } //Every time the script is run it resets the bool to false is_colliding = false; }