/// <summary>Instantiates the clicked tower into the game somewhere.</summary> private void TowerClicked(GameObject prefab) { // Return if already purchasing to avoid nasty bugs :P if (selectedTowerForPurchase != null || bSelling) { return; } AudioHandler.ClickSound(); GameObject ins = Object.Instantiate(prefab, TowerManager.towersContainer); ins.GetComponent <RectTransform>().anchoredPosition = new Vector2(GameManager.CANVAS_WIDTH / 2.0f, GameManager.CANVAS_HEIGHT / -2.0f); ins.SetActive(true); selectedTowerForPurchase = ins.GetComponent <ITower>(); selectedCp = ins.GetComponent <TowerClickPoint>(); selectedCp.enabled = false; // Don't allow clicking for sell while purchasing. selectedTd = selectedTowerForPurchase.GetRangeCircle().AddComponent <TowerDisplay>(); // To allow dragging. selectedTd.Initialise(); selectedTowerForPurchase.ShowRangeCircle(true); selectedTowerForPurchase.SetEnabled(false); // Show the buy options buyOptions.alpha = 1.0f; buyOptions.gameObject.SetActive(true); label_selectedInfoHeader.text = selectedTowerForPurchase.MyInfo().towerName; label_selectedInfoContent.text = selectedTowerForPurchase.MyInfo().towerDescription; bBuying = true; }
protected virtual IEnumerator AnimateAttack(TowerDisplay tower) { if (tower == null || tower is Object && tower.Equals(null)) { yield break; } yield return(StartCoroutine(AnimateAttack())); if (tower == null || tower is Object && tower.Equals(null)) { yield break; } var atkPwrVal = attackPower.GetValue() * (1 + technologyManager.meleeDamageRate); tower.TakeDamage(atkPwrVal, this); if (AnimationIdleIsNotNull() && !dead) { var hitFn = animationAttack.events.FirstOrDefault(x => x.functionName == "Hit"); if (hitFn != null) { yield return(new WaitForSeconds(animationAttack.length - hitFn.time)); } animator.Play(animationIdle.name, 0); } }
private void Awake() { Debug.Assert(towerDisplayTemplate, "Tower Display Template not provided"); if (!towerDisplayTemplate) { return; } TowerBase[] towers = Resources.LoadAll <TowerBase>(TOWERS_FOLDER).OrderBy(x => x.towerCost).ToArray(); foreach (TowerBase t in towers) { TowerDisplay display = Instantiate(towerDisplayTemplate, transform); { RadioSelect rad = display.GetComponent <RadioSelect>(); if (rad) { rad.additionalData = t; } } display.Load(t); } }
private void HideBuyOptions() { selectedTowerForPurchase = null; selectedTd = null; label_selectedInfoHeader.text = string.Empty; label_selectedInfoContent.text = string.Empty; buyOptions.alpha = 0.0f; buyOptions.gameObject.SetActive(false); bBuying = false; }
public virtual void TakeDamage(float damage, TowerDisplay damagedBy) { if (dead) { return; } hp -= damage; StartCoroutine(_shake.Shake()); if (hp <= 0) { dead = true; Debug.Log(name + " being killed!"); OnDeath(damagedBy); allies.Remove(this); } }
protected virtual IEnumerator Go() { while (gameObject != null && !gameObject.Equals(null) && !dead) { detectedEnemies = DetectEnemies(); if (detectedEnemies.Any()) { if (AnimationIdleIsNotNull() && !dead) { animator.Play(animationIdle.name, 0); } isStopMove = true; yield return(StartCoroutine(PreAttack())); yield return(StartCoroutine(AnimateAttack(detectedEnemies))); yield return(StartCoroutine(PostAttack())); } else { _detectedTower = DetectEnemyTower(); if (_detectedTower != null) { if (AnimationIdleIsNotNull() && !dead) { animator.Play(animationIdle.name, 0); } isStopMove = true; yield return(StartCoroutine(PreAttack())); yield return(StartCoroutine(AnimateAttack(_detectedTower))); yield return(StartCoroutine(PostAttack())); } else { if (AnimationWalkIsNotNull() && !dead) { animator.Play(animationWalk.name, 0); } isStopMove = false; Move(); yield return(new WaitForFixedUpdate()); } } } }
protected override IEnumerator AnimateAttack(TowerDisplay tower) { if (tower == null || tower is Object && tower.Equals(null)) { yield break; } if (AnimationAttackIsNotNull()) { yield return(StartCoroutine(PrepareAnimateLaunch())); } // var projectileIns = Instantiate<ProjectileObject> (projectileObjectPrefab, _projectilePoint.position, Quaternion.identity); // projectileIns.direction = direction; // // t = h / (uB-uA) // var h = tower.transform.position.x - projectileIns.transform.position.x; // var u = projectileIns.initialVelocity * settings.deltaSpeed * settings.deltaMoveStep * settings.deltaProjectileMoveStep; // var predictedTime = h / u; // Destroy (projectileIns.gameObject, predictedTime); // yield return new WaitForSeconds (predictedTime); if (tower != null && tower is Object && !tower.Equals(null)) { var projectileIns = Instantiate <ProjectileObject> (projectileObjectPrefab, _projectilePoint.position, Quaternion.identity); projectileIns.direction = direction; var deltaDistance = Vector3.zero; var stopPos = new Vector3(transform.position.x, transform.position.y, transform.position.z); projectileIns.Launch(tower.transform.position, deltaDistance, stopPos, () => { if (tower) { var atkPwrVal = attackPower.GetValue() * (1 + technologyManager.rangeDamageRate); tower.TakeDamage(atkPwrVal, this); } }); } // if (AnimationIdleIsNotNull () && !dead) // { // var launchFn = animationAttack.events.FirstOrDefault (x => x.functionName == "Launch"); // if (launchFn != null) // { // yield return new WaitForSeconds (animationAttack.length - launchFn.time); // } // animator.Play (animationIdle.name, 0); // } }
GameObject setTowerDisplay(GameObject prefab, TowerDisplay towerDisplay) { GameObject go = prefab; if (towerDisplay.IsEnable) { go.transform.GetChild(0).GetComponent <RawImage>().texture = towerDisplay.EnableSprite.texture; } else { go.transform.GetChild(0).GetComponent <RawImage>().texture = towerDisplay.DisableSprite.texture; } GameObject priceGO = go.transform.GetChild(1).gameObject; if (towerDisplay.Price.Coins.ContainsKey(CoinType.Gold)) { priceGO.transform.GetChild(0).GetChild(1).GetComponent <Text>().text = towerDisplay.Price.Coins[CoinType.Gold].Number.ToString(); // TODO: onClick button buy tower priceGO.transform.GetChild(0).GetComponent <Button>().onClick.AddListener(OnClick); } else { priceGO.transform.GetChild(0).gameObject.SetActive(false); } if (towerDisplay.Price.Coins.ContainsKey(CoinType.Gem)) { priceGO.transform.GetChild(1).GetChild(1).GetComponent <Text>().text = towerDisplay.Price.Coins[CoinType.Gem].Number.ToString(); // TODO: onClick button buy tower priceGO.transform.GetChild(0).GetComponent <Button>().onClick.AddListener(OnClick); } else { priceGO.transform.GetChild(1).gameObject.SetActive(false); } priceGO.transform.SetParent(go.transform.GetChild(1)); return(go); }
public Game(int diskCount) { _towers = new Towers(diskCount); _display = new TowerDisplay(_towers); _optimalMoveCount = (1 << diskCount) - 1; }
public virtual void OnDeath(TowerDisplay damagedBy) { OnDeath(); }
public virtual void Attack(TowerDisplay tower) { }