public void Start() { player = GetComponent <Player>(); Platform.Clicked.AddListener(DisplayBuildMenu); BuildButton.Clicked.AddListener(Build); CancelButton.Clicked.AddListener(CancelBuildMenu); canvas = buildMenu.GetComponent <Canvas>(); cam = Camera.main; buildPanelTransform = buildMenu.transform.GetChild(0); }
// Called when the left mouse button is first clicked void OnLeftClick() { if (EventSystem.current.IsPointerOverGameObject()) { return; } Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit2D hit; GameObject hitObject; hit = Physics2D.GetRayIntersection(ray); if (buildMenu.gameObject.activeSelf) { if (!selectedUnit.IsWithinOneTile(selectedTilePos)) { buildMenu.GetComponent <BuildMenu>().CloseMenu(); UnselectUnit(); } return; } // Handles selection of units if (hit.collider != null) { hitObject = hit.collider.gameObject; if (hitObject.GetComponent <MobileUnit>() != null) { SelectUnit(hitObject); return; } else { targetedUnitMenu.gameObject.SetActive(false); } } else { targetedUnitMenu.CancelAttackButton(); } // Handles movement of the selected unit if (selectedUnit != null) { if (selectedUnit.IsWithinOneTile(selectedTilePos) && selectedUnit.canMove) { if (selectedUnit.MoveToTile(selectedTilePos.x, selectedTilePos.y)) { UnselectUnit(); } } else { UnselectUnit(); } return; } }
void Update() { if (castle || outpost || barracks || house || TP || AC || mineshaft || bank || tavern || PUB || storage || market || DT || BT || WWall || RWall || blacksmith || TC || farm || spikes) { if (currentPlaceholder != null) { currentPlaceholder.transform.localEulerAngles = new Vector3(currentPlaceholder.transform.localEulerAngles.x, buildingDegrees * degreesOfRotation, currentPlaceholder.transform.localEulerAngles.z); } } if (castle) //if LOGIC returns true, that means it has to stop the loop by turning off the building bool { state = Logic(CastlePrefab, upOffsetCastle, false, CWCost, CRCost, CICost, 0, CGCost, 0); if (state == LogicExitState.Placed) { castle = false; } else if (state == LogicExitState.Placed) { castle = false; } } else if (outpost) { state = Logic(OutpostPrefab, upOffsetOutpost, false, outpostWoodCost, outpostRockCost, outpostIronCost, 0, 0, 0); if (state == LogicExitState.Placed) { outpost = false; outpostWoodCost += (int)(outpostWoodCost * costMultiplyer); outpostRockCost += (int)(outpostRockCost * costMultiplyer); outpostIronCost += (int)(outpostIronCost * costMultiplyer); BuildMenu.GetComponent <BuildMenu>().UpdateAllCosts(); } else if (state == LogicExitState.Placed) { outpost = false; } } else if (spikes) { state = Logic(Spikes, upOffsetSpikes, false, SpikesWoodCost, 0, 0, 0, 0, 0); if (state == LogicExitState.Placed) { spikes = false; SpikesWoodCost += (int)(SpikesWoodCost * costMultiplyer); BuildMenu.GetComponent <BuildMenu>().UpdateAllCosts(); } else if (state == LogicExitState.Placed) { spikes = false; } } else if (barracks) { state = Logic(BarracksPrefab, upOffsetBarracks, true, BarrWCost, BarrRCost, BarrICost, 0, BarrGCost, BarrHCost); if (state == LogicExitState.Placed) { barracks = false; BarrWCost += (int)(BarrWCost * costMultiplyer); BarrRCost += (int)(BarrRCost * costMultiplyer); BarrICost += (int)(BarrICost * costMultiplyer); BarrGCost += (int)(BarrGCost * costMultiplyer); BarrHCost += (int)(BarrHCost * costMultiplyer); BuildMenu.GetComponent <BuildMenu>().UpdateAllCosts(); } else if (state == LogicExitState.Placed) { barracks = false; } } else if (TC) { state = Logic(TCPrefab, upOffsetTC, true, TCWCost, TCRCost, TCICost, 0, TCGCost, 0); if (state == LogicExitState.Placed) { TC = false; TCWCost += (int)(TCWCost * costMultiplyer); TCRCost += (int)(TCRCost * costMultiplyer); TCICost += (int)(TCICost * costMultiplyer); TCGCost += (int)(TCGCost * costMultiplyer); BuildMenu.GetComponent <BuildMenu>().UpdateAllCosts(); } else if (state == LogicExitState.Placed) { TC = false; } } else if (AC) { state = Logic(ACPrefab, upOffsetAC, false, ACWCost, ACRCost, ACICost, ACFCost, ACGCost, 0); if (state == LogicExitState.Placed) //idk if AC is solid { AC = false; ACWCost += (int)(ACWCost * costMultiplyer); ACRCost += (int)(ACRCost * costMultiplyer); ACICost += (int)(ACICost * costMultiplyer); ACFCost += (int)(ACFCost * costMultiplyer); ACGCost += (int)(ACGCost * costMultiplyer); BuildMenu.GetComponent <BuildMenu>().UpdateAllCosts(); } else if (state == LogicExitState.Placed) { AC = false; } } else if (BT) { state = Logic(BTPrefab, upOffsetBT, true, BTWCost, 0, BTICost, 0, 0, 0); if (state == LogicExitState.Placed) { BT = false; BTWCost += (int)(BTWCost * costMultiplyer); BuildMenu.GetComponent <BuildMenu>().UpdateAllCosts(); } else if (state == LogicExitState.Placed) { BT = false; } } else if (DT) { state = Logic(DTPrefab, upOffsetDT, true, DTWCost, DTRCost, 0, 0, DTGCost, 0); if (state == LogicExitState.Placed) { DT = false; DTWCost += (int)(DTWCost * costMultiplyer); DTRCost += (int)(DTRCost * costMultiplyer); DTICost += (int)(DTICost * costMultiplyer); DTGCost += (int)(DTGCost * costMultiplyer); BuildMenu.GetComponent <BuildMenu>().UpdateAllCosts(); } else if (state == LogicExitState.Placed) { DT = false; } } else if (storage) { state = Logic(StoragePrefab, upOffsetStorage, true, storageWoodCost, storageRockCost, 0, 0, 0, 0); if (state == LogicExitState.Placed) { storage = false; storageWoodCost += (int)(storageWoodCost * costMultiplyer); storageRockCost += (int)(storageRockCost * costMultiplyer); BuildMenu.GetComponent <BuildMenu>().UpdateAllCosts(); } else if (state == LogicExitState.Placed) { storage = false; } } else if (tavern) { state = Logic(TavernPrefab, upOffsetTavern, true, tavernWoodCost, tavernRockCost, tavernIronCost, tavernFoodCost, tavernGoldCost, tavernHideCost); if (state == LogicExitState.Placed) { tavern = false; tavernWoodCost += (int)(tavernWoodCost * costMultiplyer); tavernRockCost += (int)(tavernRockCost * costMultiplyer); tavernIronCost += (int)(tavernIronCost * costMultiplyer); tavernFoodCost += (int)(tavernFoodCost * costMultiplyer); tavernGoldCost += (int)(tavernGoldCost * costMultiplyer); tavernHideCost += (int)(tavernHideCost * costMultiplyer); BuildMenu.GetComponent <BuildMenu>().UpdateAllCosts(); } else if (state == LogicExitState.Placed) { tavern = false; } } else if (TP) { state = Logic(TPPrefab, upOffsetTP, true, TPWoodCost, TPRockCost, TPIronCost, TPFoodCost, TPGoldCost, TPHideCost); if (state == LogicExitState.Placed) { TP = false; TPWoodCost += (int)(TPWoodCost * costMultiplyer); TPRockCost += (int)(TPRockCost * costMultiplyer); TPIronCost += (int)(TPIronCost * costMultiplyer); TPFoodCost += (int)(TPFoodCost * costMultiplyer); TPGoldCost += (int)(TPGoldCost * costMultiplyer); TPHideCost += (int)(TPHideCost * costMultiplyer); BuildMenu.GetComponent <BuildMenu>().UpdateAllCosts(); } else if (state == LogicExitState.Placed) { TP = false; } } else if (mineshaft) { state = Logic(MSPrefab, upOffsetMS, true, MSWCost, 0, MSICost, 0, MSGCost, MSHCost); if (state == LogicExitState.Placed) { mineshaft = false; MSWCost += (int)(MSWCost * costMultiplyer); MSICost += (int)(MSICost * costMultiplyer); MSGCost += (int)(MSGCost * costMultiplyer); MSHCost += (int)(MSHCost * costMultiplyer); BuildMenu.GetComponent <BuildMenu>().UpdateAllCosts(); } else if (state == LogicExitState.Placed) { mineshaft = false; } } else if (WWall) { state = Logic(WWallPrefab, upOffsetWWall, true, WWallCost, 0, 0, 0, 0, 0); if (state == LogicExitState.Placed) { WWall = false; WWallCost += (int)(WWallCost * costMultiplyer); BuildMenu.GetComponent <BuildMenu>().UpdateAllCosts(); } else if (state == LogicExitState.Placed) { WWall = false; } } else if (RWall) { state = Logic(RWallPrefab, upOffsetRWall, false, 0, RWallCostRock, RWallCostIron, 0, 0, 0); if (state == LogicExitState.Placed) { RWall = false; RWallCostRock += (int)(RWallCostRock * costMultiplyer); RWallCostIron += (int)(RWallCostIron * costMultiplyer); BuildMenu.GetComponent <BuildMenu>().UpdateAllCosts(); } else if (state == LogicExitState.Placed) { RWall = false; } } else if (house) { state = Logic(HousePrefab, upOffsetHouse, true, houseWoodCost, houseRockCost, houseIronCost, houseFoodCost, 0, 0); if (state == LogicExitState.Placed) { house = false; houseWoodCost += (int)(houseWoodCost * costMultiplyer); houseRockCost += (int)(houseRockCost * costMultiplyer); houseIronCost += (int)(houseIronCost * costMultiplyer); houseFoodCost += (int)(houseFoodCost * costMultiplyer); BuildMenu.GetComponent <BuildMenu>().UpdateAllCosts(); } else if (state == LogicExitState.Placed) { house = false; } } else if (market) { state = Logic(MarketPrefab, upOffsetMarket, false, marketWoodCost, marketRockCost, marketIronCost, marketFoodCost, 0, 0); if (state == LogicExitState.Placed) { market = false; } else if (state == LogicExitState.Placed) { market = false; } } else if (blacksmith) { state = Logic(BlacksmithPrefab, upOffsetBlacksmith, true, BSWoodCost, BSRockCost, BSIronCost, BSFoodCost, BSGoldCost, BSHideCost); if (state == LogicExitState.Placed) { blacksmith = false; BSWoodCost += (int)(BSWoodCost * costMultiplyer); BSRockCost += (int)(BSRockCost * costMultiplyer); BSIronCost += (int)(BSIronCost * costMultiplyer); BSFoodCost += (int)(BSFoodCost * costMultiplyer); BSGoldCost += (int)(BSGoldCost * costMultiplyer); BSHideCost += (int)(BSHideCost * costMultiplyer); BuildMenu.GetComponent <BuildMenu>().UpdateAllCosts(); } else if (state == LogicExitState.Placed) { blacksmith = false; } } else if (PUB) { state = Logic(PUBPrefab, upOffsetPUB, true, PUBWoodCost, PUBRockCost, PUBIronCost, 0, PUBGoldCost, 0); if (state == LogicExitState.Placed) { PUB = false; } else if (state == LogicExitState.Placed) { PUB = false; } } else if (farm) { state = Logic(FarmPrefab, upOffsetFarm, false, FWCost, FRCost, FICost, FFCost, 0, FHCost); if (state == LogicExitState.Placed) { farm = false; FWCost += (int)(FWCost * costMultiplyer); FRCost += (int)(FRCost * costMultiplyer); FICost += (int)(FICost * costMultiplyer); FFCost += (int)(FFCost * costMultiplyer); FHCost += (int)(FHCost * costMultiplyer); BuildMenu.GetComponent <BuildMenu>().UpdateAllCosts(); } else if (state == LogicExitState.Placed) { farm = false; } } else if (bank) { state = Logic(BankPrefab, upOffsetBank, false, BWCost, BRCost, BICost, BFCost, BGCost, 0); if (state == LogicExitState.Placed) { bank = false; BWCost += (int)(BWCost * costMultiplyer); BRCost += (int)(BRCost * costMultiplyer); BICost += (int)(BICost * costMultiplyer); BFCost += (int)(BFCost * costMultiplyer); BGCost += (int)(BGCost * costMultiplyer); BuildMenu.GetComponent <BuildMenu>().UpdateAllCosts(); } else if (state == LogicExitState.Placed) { bank = false; } } }
void Update() { //my cheats :D if (Input.GetKey(KeyCode.R) && Input.GetKey(KeyCode.O) && Input.GetKeyDown(KeyCode.L)) { gameObject.GetComponent <PlayerStats>().Add("Wood", 100); gameObject.GetComponent <PlayerStats>().Add("Rock", 100); gameObject.GetComponent <PlayerStats>().Add("Iron", 100); gameObject.GetComponent <PlayerStats>().Add("Food", 100); gameObject.GetComponent <PlayerStats>().Add("Gold", 100); gameObject.GetComponent <PlayerStats>().Add("Hide", 100); Master.GetComponent <GameMaster>().Add("Wood", 100); Master.GetComponent <GameMaster>().Add("Rock", 100); Master.GetComponent <GameMaster>().Add("Iron", 100); Master.GetComponent <GameMaster>().Add("Food", 100); Master.GetComponent <GameMaster>().Add("Gold", 100); Master.GetComponent <GameMaster>().Add("Hide", 100); Debug.Log("Sneaky c**t you just cheated"); Master.GetComponent <GameMaster>().PassErrorMessage("Please don't cheat ;-;"); } //all the actual code if (canSwing == false && isBlocking == false) { if (x >= swordTimer) { x = 0; canSwing = true; } else { x++; } } if (canHammer == false) { if (y >= hammerTimer) { y = 0; canHammer = true; } else { y++; } } if (Input.GetKeyDown(KeyCode.W) || Input.GetKeyDown(KeyCode.S) || Input.GetKeyDown(KeyCode.D) || Input.GetKeyDown(KeyCode.A)) { if (sound.isPlaying == false) { sound.clip = walk; sound.Play(); sound.loop = true; } } if (Input.GetKeyUp(KeyCode.W) || Input.GetKeyUp(KeyCode.S) || Input.GetKeyUp(KeyCode.D) || Input.GetKeyUp(KeyCode.A)) { if (Input.GetKey(KeyCode.W) == false && Input.GetKey(KeyCode.S) == false && Input.GetKey(KeyCode.D) == false && Input.GetKey(KeyCode.A) == false) { if (sound.isPlaying) { sound.clip = walk; sound.Stop(); sound.loop = false; } } } if (Input.GetKeyDown(KeyCode.LeftShift)) { gameObject.transform.parent.GetComponent <PlayerControler>().movementSpeed = GetComponent <PlayerStats>().sprintSpeed; isSprinting = true; } else if (Input.GetKeyUp(KeyCode.LeftShift)) { gameObject.transform.parent.GetComponent <PlayerControler>().movementSpeed = GetComponent <PlayerStats>().walkSpeed; isSprinting = false; } if (isSprinting) { if (s > 0) { sprintBar.GetComponent <Transform>().localScale = new Vector3(1, s / GetComponent <PlayerStats>().sprintMax, 1); s--; } else { gameObject.transform.parent.GetComponent <PlayerControler>().movementSpeed = GetComponent <PlayerStats>().walkSpeed; isSprinting = false; } } else if (s < GetComponent <PlayerStats>().sprintMax) { s += GetComponent <PlayerStats>().sprintRegen; sprintBar.GetComponent <Transform>().localScale = new Vector3(1, s / GetComponent <PlayerStats>().sprintMax, 1); } if (Input.GetKeyDown(KeyCode.Escape)) { Esc(); } //if(selected.name == "PickAxe_2"){ //Debug.Log (selected.name); //gameObject.GetComponent <Gather> ().canGather = true; if (Input.GetKeyDown(KeyCode.R)) { constB.GetComponent <ConstructBuilding>().RotateBuilding(); } if (Input.GetKeyDown(KeyCode.T)) { distance = gameObject.GetComponent <PlayerStats> ().interactDistance; if (Physics.Raycast(gameObject.transform.position, transform.forward, out hit, distance)) { if (hit.collider.CompareTag("House")) { hit.collider.GetComponent <House> ().CollectTax(); } } } if (Input.GetKeyDown(KeyCode.E)) { distance = gameObject.GetComponent <PlayerStats> ().interactDistance; if (Physics.Raycast(gameObject.transform.position, transform.forward, out hit, distance)) { if (hit.collider.CompareTag("BaseBuilding")) { hit.collider.GetComponent <BaseBuilding> ().OpenMenu(); } else if (hit.collider.CompareTag("Outpost")) //just put the other buildings name in the string { hit.collider.GetComponent <Outpost> ().OpenMenu(); } else if (hit.collider.CompareTag("Market")) //just put the other buildings name in the string { hit.collider.GetComponent <Market> ().OpenMenu(); } else if (hit.collider.CompareTag("House")) //just put the other buildings name in the string { hit.collider.GetComponent <House> ().OpenMenu(); } else if (hit.collider.CompareTag("PlayerUpgradesBuilding")) //just put the other buildings name in the string { hit.collider.GetComponent <PlayerUpgradesBuilding> ().OpenMenu(); } else if (hit.collider.CompareTag("Farm")) //just put the other buildings name in the string { hit.collider.GetComponent <Farm> ().OpenMenu(); } else if (hit.collider.CompareTag("Bank")) //just put the other buildings name in the string { hit.collider.GetComponent <Bank> ().OpenMenu(); } else if (hit.collider.CompareTag("Storage")) //just put the other buildings name in the string { hit.collider.GetComponent <StorageBuilding> ().OpenMenu(); } else if (hit.collider.CompareTag("Tavern")) //just put the other buildings name in the string { hit.collider.GetComponent <Tavern> ().OpenMenu(); } else if (hit.collider.CompareTag("Blacksmith")) //just put the other buildings name in the string { hit.collider.GetComponent <Blacksmith> ().OpenMenu(); } else if (hit.collider.CompareTag("MineShaft")) //just put the other buildings name in the string { hit.collider.GetComponent <MineShaft> ().OpenMenu(); } else if (hit.collider.CompareTag("TreePlantation")) //just put the other buildings name in the string { hit.collider.GetComponent <TreePlantation> ().OpenMenu(); } else if (hit.collider.CompareTag("Wall")) //just put the other buildings name in the string { hit.collider.GetComponent <Wall> ().OpenMenu(); } else if (hit.collider.CompareTag("Barracks")) //just put the other buildings name in the string { hit.collider.GetComponent <Barracks> ().OpenMenu(); } else if (hit.collider.CompareTag("AnimalCoop")) //just put the other buildings name in the string { hit.collider.GetComponent <AnimalCoop> ().OpenMenu(); } else if (hit.collider.CompareTag("Castle")) //just put the other buildings name in the string { hit.collider.GetComponent <Castle> ().OpenMenu(); } else if (hit.collider.CompareTag("TrainingCamp")) //just put the other buildings name in the string { hit.collider.GetComponent <TrainingCamp> ().OpenMenu(); } else if (hit.collider.CompareTag("DefenceTower")) //just put the other buildings name in the string { hit.collider.transform.Find("Detector").GetComponent <DefenceTower> ().OpenMenu(); } else if (hit.collider.CompareTag("BellTower")) //just put the other buildings name in the string { hit.collider.transform.Find("Detector").GetComponent <BellTower> ().OpenMenu(); } } } else if (Input.GetKeyDown(KeyCode.B)) { showBuild = !showBuild; if (showBuild) { BuildMenu.GetComponent <ConstructBuilding>().OpenMenu(); } else { BuildMenu.GetComponent <ConstructBuilding>().CloseMenu(); } } //} if (selected.name == "Sword") { //gameObject.GetComponent <Gather> ().canGather = false; //Debug.Log (selected.name); //what to do when sword is selected... if (Input.GetKeyDown(KeyCode.V)) { foreach (GameObject t in myTroops) { t.GetComponent <Troop>().Deselect(); } myTroops.Clear(); tmpTroops = GameObject.FindGameObjectsWithTag("SSTroop"); foreach (GameObject t in tmpTroops) { if (t.layer == 8) //friendly troop { t.GetComponent <Troop>().Select(); myTroops.Add(t); } } tmpTroops = GameObject.FindGameObjectsWithTag("ShieldTroop"); foreach (GameObject t in tmpTroops) { if (t.layer == 8) //friendly troop { t.GetComponent <Troop>().Select(); myTroops.Add(t); } } } else if (Input.GetKeyDown(KeyCode.Tab)) { foreach (GameObject t in myTroops) { t.GetComponent <Troop>().Deselect(); } myTroops.Clear(); tmpTroops = GameObject.FindGameObjectsWithTag("SSTroop"); foreach (GameObject t in tmpTroops) { if (t.layer == 8 && t.GetComponent <Renderer>().isVisible) //if friendly troop is visible by any camera in the scene then select that troop { t.GetComponent <Troop>().Select(); myTroops.Add(t); } } tmpTroops = GameObject.FindGameObjectsWithTag("ShieldTroop"); foreach (GameObject t in tmpTroops) { if (t.layer == 8 && t.GetComponent <Renderer>().isVisible) //if friendly troop is visible by any camera in the scene then select that troop { t.GetComponent <Troop>().Select(); myTroops.Add(t); } } } if (Input.GetKeyDown(KeyCode.Mouse0) && Input.GetKey(KeyCode.LeftControl) == false) { Swing(); } if (Input.GetKeyDown(KeyCode.Mouse1) && Input.GetKey(KeyCode.LeftControl) == false) { isBlocking = true; Block(); } if (Input.GetKeyUp(KeyCode.Mouse1) && Input.GetKey(KeyCode.LeftControl) == false) { isBlocking = false; Block(); } if (Input.GetKey(KeyCode.LeftControl) && Input.GetKey(KeyCode.Mouse0)) //selects troops //while buttons are being pressed //Debug.Log ("CTRL and mouse0 are being held down"); { if (Physics.Raycast(gameObject.transform.position, transform.forward, out hit, troopSelectDistance)) { if (hit.collider.gameObject.layer == 8) { addToList = true; foreach (GameObject troop in myTroops) { if (troop == hit.collider.gameObject) { addToList = false; break; } else { addToList = true; } } if (addToList) { myTroops.Add(hit.collider.gameObject); hit.collider.gameObject.GetComponent <Troop>().Select(); Debug.Log("Troop selected: " + hit.collider.gameObject.name); } } } } if (Input.GetKeyDown(KeyCode.Mouse2) && Input.GetKey(KeyCode.LeftControl) == false) //middle mouse clears the selection { foreach (GameObject troop in myTroops) { troop.GetComponent <Troop>().Deselect(); } myTroops.Clear(); } if (Input.GetKeyDown(KeyCode.Mouse2) && Input.GetKey(KeyCode.LeftControl)) //middle mouse + ctrl makes troops attack an enemy or charge at a building { if (Physics.Raycast(gameObject.transform.position, transform.forward, out hit, 1000f)) { if (hit.collider.gameObject.layer == 9 || hit.collider.gameObject.layer == 10) //9 = enemy layer, 10 = enemy building { Instantiate(Waypoint, hit.point, Quaternion.identity, GameObject.Find("GameMaster").transform); if (myTroops.Count == 0) { Master.GetComponent <GameMaster>().PassErrorMessage("You have not selected troops to command!"); } else { foreach (GameObject troop in myTroops) { if (troop != null) { troop.GetComponent <Troop>().Charge(hit.collider.gameObject); } } } } } } if (Input.GetKey(KeyCode.LeftControl) && Input.GetKeyDown(KeyCode.Mouse1)) //right mouse + ctrl makes troops move where you are pointing //Debug.Log ("Pressed"); { if (Physics.Raycast(gameObject.transform.position, transform.forward, out hit, 1000f)) { //Debug.Log (hit.collider.gameObject.name); if (hit.collider.gameObject.tag == "Ground") //if pointing at the ground { Instantiate(Waypoint, hit.point, Quaternion.identity, GameObject.Find("GameMaster").transform); if (myTroops.Count == 0) { Master.GetComponent <GameMaster>().PassErrorMessage("You have not selected troops to command!"); } else { foreach (GameObject troop in myTroops) { if (troop != null) { troop.GetComponent <Troop>().Move(hit.point); } } } } } } } if (selected.name == "Hammer") { if (Input.GetKey(KeyCode.Mouse0)) { if (canHammer) { Hammer.GetComponent <Animator>().SetTrigger("SwingHammer"); if (Physics.Raycast(gameObject.transform.position, transform.forward, out hit, 10f, hammerMask)) { if (hit.collider.gameObject.GetComponent <BuildHammer>() != null) { if (hit.collider.gameObject.GetComponent <BuildHammer>().isBuilt == false) { if (hit.collider.gameObject.GetComponent <BuildHammer> ().Build(gameObject.GetComponent <PlayerStats>().hammerStrenght)) //returns true if the building is built with this hammer hit, false if you should still build it { sound.clip = hammerHit; sound.loop = false; sound.PlayDelayed(0f); //Debug.Log ("Building built!"); } sound.clip = hammerHit; sound.loop = false; sound.PlayDelayed(0f); //Debug.Log ("Pressed build"); } else { Master.GetComponent <GameMaster>().PassErrorMessage("This building has been completely built."); } } } canHammer = false; } } else if (Input.GetKeyDown(KeyCode.Mouse1)) { if (Physics.Raycast(gameObject.transform.position, transform.forward, out hit, 10f, pushObjMask)) { hit.collider.gameObject.GetComponent <Rigidbody>().AddForce(transform.forward * pushForce); } } } if (Input.GetKeyDown(KeyCode.Q)) { if (showGlobal) { GlobalValuesUIMenu.SetActive(true); } else { GlobalValuesUIMenu.SetActive(false); } showGlobal = !showGlobal; } if (Input.GetAxis("Mouse ScrollWheel") != 0) { var delta = Input.GetAxis("Mouse ScrollWheel"); //Debug.Log("SCROLLING! delta: " + delta* Time.deltaTime + " / " + Input.GetAxis("Mouse ScrollWheel")); if (delta > Input.GetAxis("Mouse ScrollWheel") * Time.deltaTime && delta >= 0) //stopping scroll up { if (i < tools.Count - 1) { i++; //toolbarSelector.transform.Translate (0, moveSelectorAmount, 0); toolbarSelector.transform.position = slots [i].position; } else { //toolbarSelector.transform.Translate (0, -moveSelectorAmount * i, 0); i = 0; toolbarSelector.transform.position = slots [i].position; } selected = tools [i]; if (selected.name == "Sword") { gameObject.GetComponent <Gather> ().canGather = false; Pick.SetActive(false); Hammer.SetActive(false); Sword.SetActive(true); PlayerShield.SetActive(true); } if (selected.name == "PickAxe_2") { gameObject.GetComponent <Gather> ().canGather = true; Pick.SetActive(true); Hammer.SetActive(false); Sword.SetActive(false); PlayerShield.SetActive(false); } if (selected.name == "Hammer") { gameObject.GetComponent <Gather> ().canGather = false; Pick.SetActive(false); Hammer.SetActive(true); Sword.SetActive(false); PlayerShield.SetActive(false); } //Debug.Log ("Scrolled up! Selected: " + selected.name); } else if (delta * Time.deltaTime > Input.GetAxis("Mouse ScrollWheel") && delta <= 0) //stopping scroll down { if (i > 0) { i--; //toolbarSelector.transform.Translate (0, -moveSelectorAmount, 0); toolbarSelector.transform.position = slots [i].position; //Debug.Log ("i: " + i); } else { i = tools.Count - 1; //toolbarSelector.transform.Translate (0, moveSelectorAmount * i, 0); toolbarSelector.transform.position = slots [i].position; //Debug.Log ("i: " + i); } selected = tools [i]; if (selected.name == "Sword") { gameObject.GetComponent <Gather> ().canGather = false; Pick.SetActive(false); Hammer.SetActive(false); Sword.SetActive(true); PlayerShield.SetActive(true); } if (selected.name == "PickAxe_2") { gameObject.GetComponent <Gather> ().canGather = true; Pick.SetActive(true); Hammer.SetActive(false); Sword.SetActive(false); PlayerShield.SetActive(false); } if (selected.name == "Hammer") { gameObject.GetComponent <Gather> ().canGather = false; Pick.SetActive(false); Hammer.SetActive(true); Sword.SetActive(false); PlayerShield.SetActive(false); } //Debug.Log ("Scrolled down! Selected: " + selected.name); } } }