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 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; }