internal IEnumerator Spawning(string Pass, float Interval) { if (System.String.Equals(Pass, "SpawnStage")) //Spawn enemies in onstage stage { for (int i = 0; i <= Stages[OnStage].Length - 1; i++) { yield return(new WaitForSeconds(Interval)); SpawnBaddie(Stages[OnStage][i]); if (i == (Stages[OnStage].Length - 1)) { StartCoroutine(Spawning("NextStage", 3)); } } OnStage++; } else if (System.String.Equals(Pass, "NextStage")) //Prepare for next stage { for (int i = 0; i <= Interval; i++) { yield return(new WaitUntil(() => GameObject.Find("EnemyController").transform.childCount == 1)); //wait for current stage enemies to be destroyed if ((Interval - i) == 0) { Stages.Add(GenerateStage()); GameManager.PushToEventLog("Stage " + OnStage.ToString()); } else if (OnStage != 0 && i == 0) { GameManager.PushToEventLog("Stage Completed \nGold + " + OnStage * 10); GameManagerStuff.Currency += (OnStage * 3); GameManager.PushToEventLog("Next Stage in " + (Interval - i).ToString()); GameManagerStuff.Score += LevelDifficulty; } else { GameManager.PushToEventLog("Next Stage in " + (Interval - i).ToString()); yield return(new WaitForSeconds(1)); } } StartCoroutine(Spawning("SpawnStage", (3 * Mathf.Pow(0.8f, OnStage) + 0.15f))); //time between each unit spawns decreases as the stage increases, never dips below 0.25f } }
internal TowerID CurrentTowerID; //this is used internally void Start() //Use this for initialization { GameManager = GameObject.Find("GameManager").GetComponent <GameManagerStuff>(); EnemyController = GameObject.Find("EnemyController"); ShootSound = (AudioClip)Resources.Load("Audio/Sound Effects/RandomSfx/appleeat"); if (GameManagerStuff.Currency - Cost < 0) { GameManager.PushToEventLog("Not Enough Gold."); Destroy(gameObject); } else { GameManagerStuff.Currency -= Cost; } StartCoroutine(Fire()); LastTowerSelected = gameObject; }
void Update()// Update is called once per frame { if (Indicator != null) { Indicator.GetComponent <MeshRenderer>().material.color = Color.Lerp(Color.black, Color.white, Mathf.PingPong(Time.time, 1)); //Indicator flashing float scaler = (Mathf.PingPong(Time.time, 1) + 9) / 10; //Scaler value of between 0.9 to 1 and back Indicator.transform.localScale = new Vector3(scaler, scaler, 1); //Pulsing scale Indicator.transform.position = IndPlacement - Indicator.GetComponent <Renderer>().bounds.size / 2 + Vector3.up; //Dynamic repositioning so that the indicator is always in the middle of the square } if (Input.GetMouseButtonDown(1)) //Right clicked { RaycastHit hit; //Ray stuff for damage text popups if ((Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit))) //ray from camera to screen point { Destroy(Indicator); if (hit.transform.gameObject == Indicator) //On indicator { if (Indicator.transform.parent.Find("Tower") == null) //Is square built on already? { if (GameManagerStuff.TowersBuilt < MaxTowers) //build tower { GameObject Tower = GameManager.AssignComponents("Tower", ((GameObject)Resources.Load("Construction/Tower")).transform.GetChild(0).GetComponent <MeshFilter>().sharedMesh, (Material)Resources.Load("Construction/TowerMat"), true); GameObject TowerRoof = GameManager.AssignComponents("TowerRoof", ((GameObject)Resources.Load("Construction/TowerRoof")).transform.GetChild(0).GetComponent <MeshFilter>().sharedMesh, new Material(Shader.Find("Standard")), false); TowerRoof.transform.position = Tower.transform.position + new Vector3(-0.5f, (int)(Tower.GetComponent <Collider>().bounds.size.y / 4), 1.5f); TowerRoof.transform.SetParent(Tower.transform); Tower.AddComponent <TowerBehaviour>(); Tower.GetComponent <TowerBehaviour>().SetTowerType(TowerBehaviour.TowerID.Default); Tower.GetComponent <Rigidbody>().isKinematic = true; Tower.transform.position = Indicator.transform.position + Indicator.transform.parent.GetComponent <Renderer>().bounds.extents; Tower.transform.SetParent(Indicator.transform.parent); Tower.transform.localScale /= 1.25f; GameManager.PushToEventLog("Tower Built."); AudioSource.PlayClipAtPoint(BuildSound, Camera.main.transform.position, 0.02f); GameManagerStuff.TowersBuilt++; } else { GameManager.PushToEventLog("You cannot have more \n than " + MaxTowers + " Towers."); } } else { GameManager.PushToEventLog("Tower Selected."); TowerBehaviour.LastTowerSelected = Indicator.transform.parent.GetChild(0).gameObject; } } else if (hit.transform.gameObject.name.Contains("Tower")) { GameManager.PushToEventLog("Tower Selected."); TowerBehaviour.LastTowerSelected = hit.transform.gameObject; } foreach (GameObject gridpiece in Grid) //On grid piece { if (hit.transform.gameObject == gridpiece) { SelGridPiece = hit.transform.gameObject; //Which grid piece Indicator = GameManager.AssignComponents("Indicator", CGG.DoMesh(), new Material(Shader.Find("Standard"))); Indicator.GetComponent <MeshCollider>().isTrigger = true; Indicator.transform.Rotate(90, 0, 0); Indicator.transform.SetParent(gridpiece.transform); IndPlacement = SelGridPiece.transform.position; IndPlacement += SelGridPiece.GetComponent <Renderer>().bounds.size / 2; } } } } }
private void ClickerFunc(GameObject gO) //clicker upgrade button functionality { switch (gO.name) { case "Damage": if (GameManager.CanAfford(GameManagerStuff.Cost)) { GameManagerStuff.Currency -= GameManagerStuff.Cost; GameManagerStuff.Cost = Mathf.Round(GameManagerStuff.Cost * 1.1f) + 10; GameManagerStuff.Damage -= 0.5f; } break; case "Kill Bonus": if (GameManager.CanAfford(GameManagerStuff.Cost)) { GameManagerStuff.Currency -= GameManagerStuff.Cost; GameManagerStuff.Bonus += 3; GameManagerStuff.Cost += 10; } break; case "Armour Piercing": if (GameManager.CanAfford(GameManagerStuff.Cost)) { if (GameManagerStuff.ArmourPiercingPC <= 90) { GameManagerStuff.Currency -= GameManagerStuff.Cost; GameManagerStuff.ArmourPiercingPC += 10; GameManagerStuff.Cost += 10; } else { GameManager.PushToEventLog("Armour piercing at 100%"); } } break; } }