public void InitializeTower(BuildSpot buildSpot) { var obj = Instantiate(progressbarPrefab, this.transform); obj.transform.localPosition = new Vector3(0, distanceAboveTower, 0); progressBar = obj.GetComponent <HUDTowerProgressBar>(); StartCoroutine(BuildTower()); this.buildSpot = buildSpot; }
BuildSpot GetBuildSpotFromRay() { BuildSpot spot = null; Ray ray = mainCamera.ScreenPointToRay(Input.mousePosition); RaycastHit hitInfo; if (Physics.SphereCast(ray.origin, .5f, ray.direction, out hitInfo, 500f, placeableLayer, QueryTriggerInteraction.Collide) && !IsOverUI()) { spot = hitInfo.transform.GetComponent <BuildSpot>(); } return(spot); }
void Start() { animator = gameObject.GetComponent <Animator> (); sc = FindObjectOfType <SoundController> (); buildSpot = GetComponentInParent <BuildSpot>(); foreach (ClassCannon cannon in buildSpot.cannonLibrary) { if (cannon.cannonName == gameObject.name) { range = cannon.cannonRange; fireRate = cannon.cannonFireRate; } } }
void SetTileOutLineColor(BuildSpot spot) { if (spot != null) { if (!spot.IsOccupied && !buildMenu.isMenuShowing) { Outline outlineSystem = spot.GetComponent <Outline>(); outlineSystem.enabled = true; if (buildMenu.IsPlayerInRange(spot.transform.position)) { outlineSystem.OutlineColor = inRangeColor; } else { outlineSystem.OutlineColor = outOfRangeColor; } } } }
void Update() { var spot = GetBuildSpotFromRay(); if (spot != null) { if (currentBuildSpot != null && spot != currentBuildSpot) { currentBuildSpot.GetComponentInChildren <Outline>().enabled = false; } currentBuildSpot = spot; SetTileOutLineColor(currentBuildSpot); } else { if (currentBuildSpot != null) { currentBuildSpot.GetComponentInChildren <Outline>().enabled = false; } } if (Input.GetMouseButtonDown(0) && !IsOverUI()) { BuildSpot newSpot = GetBuildSpotFromRay(); if (newSpot != null) { if (!newSpot.IsOccupied) { if (buildMenu.IsPlayerInRange(newSpot.transform.position)) { buildMenu.SetTargetBuildSpot(newSpot); } } } else { buildMenu.HideBuildMenu(); } } }
public void SetTargetBuildSpot(BuildSpot newSpot) { currentBuildSpot = newSpot; container.SetActive(true); isMenuShowing = true; }