public int turnPlaced = 0; //< The turn this tower was placed in the level #region Major Monobehaviour Functions /** * Awake is called after initialization of gameobjects prior to the start of the game. Handle initialization tasks common to all towers */ protected virtual void Awake() { // Get initialization values and set this towers basic values initValues = FindObjectOfType <ManagerIndex>(); // Get the Tower Manager towerManager = FindObjectOfType <TowerManager>(); // Get component references rangeEffect = GetComponent <TowerRangeEffect>(); }
/** * Check for a tower and apply the effects that selecting a tower should trigger * * @param hitObject GameObject The object that the raycast hit * @param isLeftMouse Bool dictating if the left mouse button was clicked or not */ private void CheckForTower(GameObject hitObject, bool isLeftMouse) { // Flag to tell us later if we actually hit a tower bool hitTower = false; // Attempt to get the TowerBase component from the object if it has one TowerBase towerTemp = hitObject.GetComponent <TowerBase>(); // Make sure that we found a TowerBase component that is active if (towerTemp != null && towerTemp.isActiveAndEnabled) { // Set flag so we know later that we hit a tower hitTower = true; // Turn off previous effect if there was one if (selectedRangeEffect != null && selectedRangeEffect != hitObject.GetComponent <TowerRangeEffect>()) { // Turn the neutral range effect off selectedRangeEffect.UpdateEffect(TowerRangeEffect.EffectState.Off); } // Set as selected tower selectedTower = towerTemp; // Get the range effect component and update it to show the neutral tower range effect selectedRangeEffect = hitObject.GetComponent <TowerRangeEffect>(); selectedRangeEffect.UpdateEffect(selectedRangeEffect.State == TowerRangeEffect.EffectState.Off ? TowerRangeEffect.EffectState.Neutral : TowerRangeEffect.EffectState.Off); } // If we did not hit a tower, remove selected tower if (!hitTower) { // Remove reference if (selectedTower != null) { selectedTower = null; } // Remove references to other components if (selectedRangeEffect != null) { // Turn the neutral range effect off selectedRangeEffect.UpdateEffect(TowerRangeEffect.EffectState.Off); selectedRangeEffect = null; } } }
/** * Handle initialization tasks common to all towers */ protected virtual void Awake() { // get component references rangeEffect = GetComponent <TowerRangeEffect>(); }