public void BuyShieldGenerator() { ZoneBuilding newZoneBuilding = (Instantiate(GeneratorRef) as GameObject).GetComponent <ZoneBuilding>(); newZoneBuilding.buildingType = ZoneBuildingType.ShieldGenerator; HandleNewObject(newZoneBuilding); }
//--------End Weapons-------------- //-----New Defensive ZoneBuildings----- public void BuyCity() { ZoneBuilding newZoneBuilding = (Instantiate(CityRef) as GameObject).GetComponent <ZoneBuilding>(); newZoneBuilding.buildingType = ZoneBuildingType.City; HandleNewObject(newZoneBuilding); }
public void BuyMissileSiloButton() { ZoneBuilding newZoneBuilding = (Instantiate(MissileSiloRef) as GameObject).GetComponent <ZoneBuilding>(); newZoneBuilding.buildingType = ZoneBuildingType.MissileSilo; HandleNewObject(newZoneBuilding); }
//-----New Weapon ZoneBuildings----- public void BuyLaserTurret() { ZoneBuilding newZoneBuilding = (Instantiate(LaserTurretRef) as GameObject).GetComponent <ZoneBuilding>(); newZoneBuilding.buildingType = ZoneBuildingType.LaserTurret; HandleNewObject(newZoneBuilding); }
public void BuyFactory() { GameObject NewObject = (Instantiate(FactoryRef) as GameObject); ZoneBuilding newZoneBuilding = NewObject.GetComponent <ZoneBuilding>(); newZoneBuilding.buildingType = ZoneBuildingType.City; HandleNewObject(newZoneBuilding); }
//--------End Defenses-------------- //-----Build Objects------ void HandleNewObject(ZoneBuilding newObj) { // Set the object to this variable so we can display it in the Update method while the user picks a location PurchasedZoneBuilding = newObj; PurchasedZoneBuilding.isActive = false; // Reset the cached list of colliders just in case they changed ControlledZoneColliders = new Dictionary <Collider, EarthZone>(); // Fetch the user's controlled earth zone colliders foreach (EarthZone controlledZone in Earth.ControlledZones) { ControlledZoneColliders.Add(controlledZone.GetComponent <Collider>(), controlledZone); } // Enabled them so we can place the object SetZoneCollidersEnabled(true); menuManager.ShopPanel.SetActive(false); }
void Update() { if (BuildMenu.PurchasedZoneBuilding == null && Input.GetMouseButtonDown(0)) { RaycastHit[] hitsInOrder = Physics.RaycastAll(Camera.main.ScreenPointToRay(Input.mousePosition)).OrderBy(h => h.distance).ToArray(); foreach (RaycastHit hit in hitsInOrder) { ZoneBuilding zoneBuildingHit = hit.collider.GetComponent <ZoneBuilding>(); if (zoneBuildingHit != null) { DisplayItem = zoneBuildingHit; DetailMenu.Display(); CurrentlyDisplayedMenu = MenuScreen.Detail; return; } } } }
void Update() { //previews placement of new building until clicked if (PurchasedZoneBuilding != null) { RaycastHit[] hitsInOrder = Physics.RaycastAll(Camera.main.ScreenPointToRay(Input.mousePosition)).OrderBy(h => h.distance).ToArray(); foreach (RaycastHit hit in hitsInOrder) { // This hit.point is the point on earth where the mouse hovers if (selectedZone == null && ControlledZoneColliders.Keys.Contains(hit.collider)) { // This should only be reached once each time the user hovers over a zone //Debug.Log("selected zone"); selectedZone = ControlledZoneColliders[hit.collider]; PurchasedZoneBuilding.ParentZone = selectedZone; PurchasedZoneBuilding.isActive = true; // Put it in the coord space of the earthzone PurchasedZoneBuilding.buildingTransform.SetParent(selectedZone.transform, true); } else if (selectedZone != null && hit.transform.tag == "Earth" && // user is hovering over controlled zone on earth ControlledZoneColliders.FirstOrDefault(key => key.Value == selectedZone).Key.bounds.Contains(hit.point)) // get the collider(key) based on the value(earthzone) { //Debug.Log("selecting spot"); // assign the up vector for the city so it the top of it faces away from earth and the bottom sits on the planet PurchasedZoneBuilding.buildingTransform.up = hit.point * 2; // set the position of this newly purchased building to the place where the mouse is PurchasedZoneBuilding.buildingTransform.position = hit.point; // If the user clicks while the newly purchased zone building is being displayed if (Input.GetMouseButton(0)) { selectedZone.ZoneBuildings.Add(PurchasedZoneBuilding); //SetZoneCollidersEnabled(false); PurchasedZoneBuilding = null; selectedZone = null; menuManager.ShopPanel.SetActive(true); } return; } } } }