// Update is called once per frame void Update() { selectionMode = SelectionManager.me.selectionMode; List <GameObject> building = SelectionManager.me.getSelected(); if (building.Count > 0) { Building b = building[0].GetComponent <Building>(); // if (b.actionsWeCanPerform != null) // { List <BuildingAction> buildActions = b.actionsWeCanPerform; if (buildActions.Count > 0) { //string queueInfo = ""; //if (b.buildingActionQueue.Count == 0) //{ // queueInfo = "No actions queued"; //} //else //{ // queueInfo = "\n" + b.buildingActionQueue[0].getProgress() + "\n" + "There are" + // (b.buildingActionQueue.Count - 1).ToString() + " actions remaining" + "\n" + b.name; //} string BuildingInfo = b.name; foreach (BuildingAction ba in buildActions) { if (isClicked) { BuildingAction baNew = (BuildingAction)Instantiate(ba, building[0].transform); building[0].gameObject.GetComponent <Building>().buildingActionQueue.Add(baNew); isClicked = false; } } } // } if (building[0].GetComponent <Building>() == true) { buildingName.text = building[0].GetComponent <Building>().name; buildingImage.sprite = building[0].GetComponent <Building>().buildingSprite; } else { Debug.Log("ffe"); } } }
//create some kind of constructor manager to put in it? void CreatingBuildings_checkForMouseClick()//this is the controller for checking if the player wants to build something { //Debug.Log("F"); // GameObject selectedBuilding = BuildingStore.me.getToBuild(); //GameObject selectedBuilding = ScrollableInventory.me.getToBuild(); GameObject selectedBuilding = AssignMethodToInventoryItems.me.getToBuild(); //Debug.Log(selectedBuilding.name); if (selectedBuilding != null)//make sure a building has been selected { Building selectedBuildScript = selectedBuilding.GetComponent <Building>(); if (selectedBuildScript != null)//make sure that selected building has a building component { Debug.Log(selectedBuildScript.name); getMultipleTilesFromCoords(selectedBuildScript.widthInTiles, selectedBuildScript.heightInTiles);//gets the tiles that the building would need //if it were placed at the current mouse position buildingPlaceCursor.GetComponent <SpriteRenderer>().sprite = selectedBuildScript.buildingSprite;//draws the cursor showing an image of the building buildingPlaceCursor.transform.position = new Vector3(Camera.main.ScreenToWorldPoint(Input.mousePosition).x, Camera.main.ScreenToWorldPoint(Input.mousePosition).y, 0); Color cursorClour = new Color(1, 1, 1, 0.5f); buildingPlaceCursor.GetComponent <SpriteRenderer>().color = cursorClour;//makes it semitranparent so that we can see through if (isCurrentLocAValidForConstruction() == true) { buildingPlaceCursor.GetComponent <SpriteRenderer>().color = cursorClour; } else { cursorClour = new Color(1, 0, 0, 0.5f); buildingPlaceCursor.GetComponent <SpriteRenderer>().color = cursorClour; } if (Input.GetMouseButtonDown(0)) { if (isCurrentLocAValidForConstruction())//creates the building there if the location is valid and the player has left clicked { createBuildingAtLocation(buildingPlaceCursor.transform.position, selectedBuildScript.widthInTiles, selectedBuildScript.heightInTiles); selectionMode = selectingModes.buildings; } } } } }
void decideSelectionMode() { if (getSelectionRaycast() == null) { selectionMode = selectingModes.units; } else { if (getSelectionRaycast().tag == "Building") { selectionMode = selectingModes.buildings; } else { selectionMode = selectingModes.units; } } }
void decideSelecetionMode() { Vector2 mousePos = new Vector2(Camera.main.ScreenToWorldPoint(Input.mousePosition).x, Camera.main.ScreenToWorldPoint(Input.mousePosition).y); RaycastHit2D raycast = Physics2D.Raycast(mousePos, Vector2.zero, 0f); try { GameObject hitObject = raycast.collider.gameObject; Debug.Log(hitObject.tag); if (hitObject.gameObject.tag == "Building") { selectionMode = selectingModes.buildings; } else if (hitObject.gameObject.tag == "Unit") { selectionMode = selectingModes.units; } } catch { } }
void Update() { selectionMode = SelectionManager.me.selectionMode; }