private void DetectObjects() { int layers = ~(1 << 8); if (Physics.Raycast(CamPos.position, CamPos.forward, out hit, 5.0F, layers, QueryTriggerInteraction.Ignore)) { //print("Facing " + hit.transform.gameObject.name); var go = hit.transform.gameObject; if (go.tag == "Carriable" && TakenObject == null) { PickupText.text = "[E] - Take " + go.name; if (Input.GetKeyUp(KeyCode.E)) { TakenObject = go; } } else if (go.tag == "Builder") { PickupText.text = "[E] - To change manufacturing item\n\n[L] - Sell " + go.name + " for $" + FactoryMachines.GetPrice(go, true); if (Input.GetKeyUp(KeyCode.E)) { var builderScript = go.GetComponent <Manufacturing>(); Manufacturing.BuilderToChangeType = go; print("You're about to change type of " + go.name); Builder1Menu.SetActive(true); MouseMove.FreezeCamera(); Cursor.visible = true; } if (Input.GetKeyUp(KeyCode.L)) { SellItem(go); } } else if (go.tag == "Interactable") { PickupText.text = "[L] - Sell " + go.name + " for $" + FactoryMachines.GetPrice(go, true); if (Input.GetKeyUp(KeyCode.L)) { SellItem(go); } } else if (go.tag == "LinkToParent") { var goParent = go.GetComponentInParent <Transform>().parent.gameObject; PickupText.text = "[L] - Sell " + goParent.name + " for $" + FactoryMachines.GetPrice(goParent, true); if (Input.GetKeyUp(KeyCode.L)) { SellItem(goParent); } } } else if (TakenObject == null) { PickupText.text = string.Empty; } }
void Update() { if (Input.GetKeyUp(KeyCode.B)) { SetMenuActive(); } if (WhatToBuild != null) { if (!HoldingItem) { if (Money.DiscardMoney(FactoryMachines.GetPrice(WhatToBuild))) { CurrentObj = Instantiate(WhatToBuild); CurrentObj.tag = "Prebuild"; HoldingItem = true; } else { Reset(); } } CurrentObj.transform.position = BuildingPositioner.transform.position; RotationLogic(); if (Input.GetKeyUp(KeyCode.E)) { if (CurrentObj.name.Contains("Builder")) { CurrentObj.tag = "Builder"; } else { CurrentObj.tag = "Interactable"; } Reset(); } } }
private void SellItem(GameObject go) { Money.AddMoney(FactoryMachines.GetPrice(go, true)); Destroy(go); }