private void OnMouseDown() { if (selectedPlace != null) { selectedPlace.TouchOn(this); selectedPlace = null; } else { TouchOn(this); selectedPlace = this; } }
void Update() { // Испускаем луч из камеры туда где сейчас находится курсор мыши Ray ray = camera.ScreenPointToRay(Input.mousePosition); // Переменная для хранения результата пересечения луча RaycastHit hit; // Если луч пересёкся с каким то объектом и этот объект имеет тег "TowerPlace" if (Physics.Raycast(ray, out hit) && hit.collider.gameObject.CompareTag("TowerPlace")) { bool isMouseDown = Input.GetMouseButtonDown(0); bool isMouseUp = Input.GetMouseButtonUp(0); TowerPlace tp = hit.collider.gameObject.GetComponent <TowerPlace>(); if (isMouseDown || isMouseUp) { if (isMouseDown) { tp.MouseDown(); } else if (isMouseUp) { tp.MouseUp(); } } else { if (currentPlace != tp) { if (currentPlace != null) { currentPlace.MouseLeave(); } tp.MouseEnter(); currentPlace = tp; } } } else { if (currentPlace != null) { currentPlace.MouseLeave(); } currentPlace = null; } }
public void OpenTowerPlaceMenu(TowerPlace place) { if (isMenuOpened) { return; } isMenuOpened = true; towerPlaceMenu.SetActive(true); Vector3 pz = Camera.main.ScreenToWorldPoint(Input.mousePosition); //pz.z = 0; towerPlaceMenu.transform.parent = gameObject.transform; selectedPlace = place; }
private void TouchOn(TowerPlace commandSender) { if (commandSender == this) { if (tower == null) { availableTowers.SetActive(!availableTowers.activeSelf); } } else { availableTowers.SetActive(false); } }
public void PurchaseTower(GameObject towerPrefab) { TowerController tc = towerPrefab.GetComponent <TowerController>(); if (gameManager.CanSpendMoney(tc.tower.purchaseCost)) { tower = Instantiate(towerPrefab, transform).GetComponent <TowerController>(); tower.transform.localPosition = Vector3.zero; tower.Init(gameManager); } TouchOn(null); selectedPlace = null; }
public void Instantiate() { playerMoneyController = GameObject.FindGameObjectWithTag("Player").GetComponent <MoneyController>(); if (playerMoneyController.numMoney >= price) { socket = gameObject.transform.parent.transform.parent.GetComponentInParent <SocketControl>().currentlySocket; // call place = socket.GetComponent <TowerPlace>(); place.InstantiateTower(prefab, speedRotation, damage, speedBullets, shootSpeed, numBullets, price); playerMoneyController.AddMoney(-price); } else { Debug.Log("no money"); } }
// Update is called once per frame public void Update() { if (AllManager.Lives <= 0) { return; } // Disable all holograms at the start of each frame DisableAllHolograms(); // Ray --> getting the player to be able to choose where to place the tower Ray mouseRay = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; // Get the actual tower prefab from towers array GameObject towerPrefab = towers[currentTower]; // This is what the raycast do if (Physics.Raycast(mouseRay, out hit)) { // where the raycast wants to hit TowerPlace place = hit.collider.GetComponent <TowerPlace>(); // Get all the unused hologram towers that is inside holograms array GameObject hologram = holograms[currentTower]; // if the place where the raycast wants to hit has no tower then just place a tower there if (place && place.noTower) { // (JUST HOVERING) // Activate hologram hologram.SetActive(true); // Position hologram on top of the tops pivotpoint hologram.transform.position = place.PlacingTheTower(); if (AllManager.Money < 10) { hologram.SetActive(false); } // (ACTUAL PLACING TOWER) // if left mouse is pressed if (Input.GetMouseButtonDown(0)) { if (AllManager.Money >= 10) { // Spawn a new tower GameObject tower = Instantiate(towerPrefab, towerParent); // Position new tower to tops tower.transform.position = place.PlacingTheTower(); // Top is no longer placeable place.noTower = false; AllManager.Money -= 10; } else { AllManager.Money = 0; } } } } }