// Update is called once per frame void Update() { if (transform.childCount == 1) { Instantiate(medicDummy, transform.position, Quaternion.identity); Destroy(gameObject); } if (mTarget) { Quaternion newRot = Quaternion.LookRotation(theTarget - transform.position, Vector3.up); newRot.y = 0; newRot.z = 0; transform.rotation = Quaternion.Lerp(transform.rotation, newRot, Time.deltaTime * mSpeed); transform.Translate(mDirection * mSpeed * Time.deltaTime); } if (gameObject.transform.position.x <= -100) { Destroy(gameObject); GameObject gc = GameObject.FindGameObjectWithTag("GameController"); if (gc) { NewSpawnWaves sw = gc.GetComponent <NewSpawnWaves>(); sw.numEnemiesRemaining--; } Destroy(gameObject); } }
// Update is called once per frame void Update() { MoveUsingDFS mus = gameObject.GetComponent <MoveUsingDFS> (); if (mus.i % 3 == 0 && mus.stop) { if ((mus.i + 3) < mus.wayPoints.Count) { int n = mus.i + Random.Range(1, 3); selectEnemy = Random.Range(0, minions.Length); GameObject eO = (GameObject)Instantiate(minions[selectEnemy], mus.wayPoints[n].transform.position, Quaternion.identity); NewSpawnWaves nsw = GameObject.FindGameObjectWithTag("GameController").GetComponent <NewSpawnWaves>(); nsw.numEnemiesRemaining++; //eO.GetComponent<EnemyStats>().mSpeed = eO.GetComponent<EnemyStats>().mSpeed; //eO.GetComponent<EnemyStats>().mHealth = eO.GetComponent<EnemyStats>().mHealth; MoveUsingDFS mud = eO.GetComponent <MoveUsingDFS>(); mud.wayPoints = gameObject.GetComponent <MoveUsingDFS>().wayPoints; mud.fromSpawner = true; mud.i = n; } } }
void OnTriggerEnter(Collider collision) { GameObject collisionObject = collision.gameObject; if (collisionObject.CompareTag("Enemy")) { //change the tower hp GameObject healthGUI = GameObject.FindGameObjectWithTag("MainCamera"); healthGUI.GetComponent <TowerHealthBar>().health -= 5; healthGUI.GetComponent <TowerHealthBar>().ChangeHealth(-1); mHealth--; if (mHealth == 0) { destroyTower = true; } comboKills = 0; killStreakTimer = theStreakTimer; GameObject gc = GameObject.FindGameObjectWithTag("GameController"); NewSpawnWaves sw = gc.GetComponent <NewSpawnWaves>(); if (collision.gameObject.name != "Shield") { sw.numEnemiesRemaining--; } int countUfoChild = 0; if (collisionObject.name == "ufo" || collisionObject.name == "ufo(Clone)") { /* * foreach(Transform child in collisionObject.transform) * { * if(child.gameObject.tag == "Enemy") * { * countUfoChild++; * //child.gameObject.transform.parent = null; * //child.gameObject.transform.position = new Vector3(child.gameObject.transform.position.x, 0.0f, child.gameObject.transform.position.z); * } * }*/ Transform [] ts = collisionObject.GetComponentsInChildren <Transform>(); for (int i = 0; i < ts.Length; i++) { if (ts[i].gameObject.tag == "Enemy" && ts[i].gameObject.name != collisionObject.gameObject.name) { Debug.Log("hello"); countUfoChild++; healthGUI.GetComponent <TowerHealthBar>().health -= 5; healthGUI.GetComponent <TowerHealthBar>().ChangeHealth(-1); } } Debug.Log(countUfoChild); sw.numEnemiesRemaining -= countUfoChild; mHealth -= countUfoChild; } Destroy(collisionObject); Debug.Log(mHealth); Debug.Log("Enemies Remaining: " + sw.numEnemiesRemaining); } }
// Update is called once per frame void Update() { if (mHealth <= 0) { if (gameObject.name == "ufo" || gameObject.name == "ufo(Clone)") { Transform [] ts = gameObject.GetComponentsInChildren <Transform>(); for (int i = 0; i < ts.Length; i++) { if (ts[i].gameObject.tag == "Enemy" && ts[i].gameObject.name != gameObject.name) { ts[i].gameObject.transform.parent = null; ts[i].gameObject.transform.position = new Vector3(ts[i].gameObject.transform.position.x, 0.0f, ts[i].gameObject.transform.position.z); Debug.Log("WWWWWWWWWWWWWWWWW"); } } /* * foreach(Transform child in gameObject.transform) * { * Debug.Log("WWWWWWWWWWWWWWWWW"); * if(child.gameObject.tag == "Enemy") * { * * child.gameObject.transform.parent = null; * child.gameObject.transform.position = new Vector3(child.gameObject.transform.position.x, 0.0f, child.gameObject.transform.position.z); * } * } */ } GameObject gc = GameObject.FindGameObjectWithTag("GameController"); if (gc) { NewSpawnWaves sw = gc.GetComponent <NewSpawnWaves>(); if (gameObject.name != "Shield") { sw.numEnemiesRemaining--; } } GameObject theTower = GameObject.FindGameObjectWithTag("TheTower"); TowerStats towerStats = theTower.GetComponent <TowerStats>(); towerStats.mScore += mResources; towerStats.mResources += mResources; Instantiate(enemyDummy, transform.position, transform.rotation); Destroy(gameObject); } if (beenSlowed) { duration -= Time.deltaTime; if (duration <= 0) { beenSlowed = false; mSpeed = origSpeed; } } }
// Update is called once per frame void Update() { if (i < wayPoints.Length) { //dir = wayPoints[i].position - transform.position; //dir = dir.normalized; walkSpeed = gameObject.GetComponent <EnemyStats>().mSpeed; transform.Translate(dir * Time.deltaTime * walkSpeed); //transform.position = Vector3.Lerp(transform.position, wayPoints[i].position, //Time.deltaTime * walkSpeed); if ((transform.position - wayPoints[i].position).sqrMagnitude <= 1.0f) { i++; if (i < wayPoints.Length) { rotateEnem.LookAt(wayPoints[i].position); rot.eulerAngles = new Vector3(rot.eulerAngles.x, rotateEnem.eulerAngles.y, rot.eulerAngles.z); dir = wayPoints[i].position - transform.position; dir = dir.normalized; } } if (i < wayPoints.Length) { if ((transform.position - wayPoints[i].position).sqrMagnitude > 2500.0f) { Debug.Log(transform.position - wayPoints[i].position); rotateEnem.LookAt(wayPoints[i].position); rot.eulerAngles = new Vector3(rot.eulerAngles.x, rotateEnem.eulerAngles.y, rot.eulerAngles.z); Debug.Log("Distance greater than 100" + (transform.position - wayPoints[i].position).sqrMagnitude); dir = wayPoints[i].position - transform.position; dir = dir.normalized; } } } else { GameObject gc = GameObject.FindGameObjectWithTag("GameController"); if (gc) { NewSpawnWaves sw = gc.GetComponent <NewSpawnWaves>(); sw.numEnemiesRemaining--; } Destroy(gameObject); } }
void destroyWall(NewSpawnWaves n) { if (wallDuration <= 0) { planeItsOn.tag = "NotTaken"; GridForUnits grid = planeItsOn.GetComponent <GridForUnits>(); if (grid) { grid.isAvailable = true; grid.whatsInside = null; grid.previous = null; grid.hasBeenVisited = false; n.wallsWereDestroyed = true; } //Destroy(gameObject); //n.wallsWereDestroyed = false; } }
// Update is called once per frame void Update() { NewSpawnWaves nsw = GameObject.FindGameObjectWithTag("GameController").GetComponent <NewSpawnWaves> (); if (nsw.waveNo > currWave) { currWave = nsw.waveNo; wallDuration--; //destroyWall(nsw); } if (wallDuration < 1) { transform.Translate(Vector3.down * Time.deltaTime * 2.0f); if (transform.position.y <= -4.0f) { destroyWall(nsw); planeItsOn.tag = "NotTaken"; Destroy(gameObject); } } }
// Update is called once per frame void Update() { if (mTarget) { Quaternion newRot = Quaternion.LookRotation(mTarget.position - transform.position, Vector3.up); newRot.y = 0; newRot.z = 0; mSpeed = gameObject.GetComponent <EnemyStats> ().mSpeed; transform.rotation = Quaternion.Lerp(transform.rotation, newRot, Time.deltaTime * mSpeed); transform.Translate(mDirection * mSpeed * Time.deltaTime); } if (gameObject.transform.position.x <= -100) { Destroy(gameObject); GameObject gc = GameObject.FindGameObjectWithTag("GameController"); if (gc) { NewSpawnWaves sw = gc.GetComponent <NewSpawnWaves>(); sw.numEnemiesRemaining--; } Destroy(gameObject); } }
// Update is called once per frame void Update() { stop = false; GameObject gct = GameObject.FindGameObjectWithTag("GameController"); if (gct) { Buy_Shoot_Modes bsm = gct.GetComponent <Buy_Shoot_Modes>(); if (bsm.thePathsHaveChanged) { //wayPoints = bsm.thePath; if (wayPoints.Contains(bsm.theTaken)) { int currI = wayPoints.IndexOf(bsm.theTaken); //Debug.Log (currI); if (currI < i) { wayPoints = bsm.dijkstraPath(wayPoints[i], wayPoints); //Debug.Log (wayPoints.Count); i = wayPoints.Count - 1; dir = wayPoints[i].transform.position - transform.position; dir = dir.normalized; } //Debug.Log ("change it"); } } /* * if(bsm.thePathsHaveChanged1) * { * if(wayPoints.Contains(bsm.theTaken)) * { * int currI = wayPoints.IndexOf(bsm.theTaken); * Debug.Log ("hello"); * if(currI <= i) * { * wayPoints = bsm.dijkstraPath(wayPoints[i]); * //Debug.Log (wayPoints.Count); * i = wayPoints.Count-1; * dir = wayPoints[i].transform.position - transform.position; * dir = dir.normalized; * } * //Debug.Log ("change it"); * } * } */ //bsm.thePathsHaveChanged = false; } if (i >= 0) { walkSpeed = gameObject.GetComponent <EnemyStats>().mSpeed; transform.Translate(dir * Time.deltaTime * walkSpeed); //transform.position = Vector3.Lerp(transform.position, wayPoints[i].position, //Time.deltaTime * walkSpeed); if ((transform.position - wayPoints[i].transform.position).sqrMagnitude <= 1.0f) { i--; stop = true; //Debug.Log(stop); if (i >= 0) { rotateEnem.LookAt(wayPoints[i].transform.position); rot.eulerAngles = new Vector3(rot.eulerAngles.x, rotateEnem.eulerAngles.y, rot.eulerAngles.z); dir = wayPoints[i].transform.position - transform.position; dir = dir.normalized; } } Debug.Log(i); if (i > 1) { if ((transform.position - wayPoints[i].transform.position).sqrMagnitude > 150.0f) { rotateEnem.LookAt(wayPoints[i].transform.position); rot.eulerAngles = new Vector3(rot.eulerAngles.x, rotateEnem.eulerAngles.y, rot.eulerAngles.z); Debug.Log("Distance greater than 100" + (transform.position - wayPoints[i].transform.position).sqrMagnitude); dir = wayPoints[i].transform.position - transform.position; dir = dir.normalized; } } } else { GameObject gc = GameObject.FindGameObjectWithTag("GameController"); if (gc) { NewSpawnWaves sw = gc.GetComponent <NewSpawnWaves>(); sw.numEnemiesRemaining--; } Destroy(gameObject); } }
void OnGUI() { //button 1 if (UnityEngine.GUI.Button(new Rect(Screen.width / 100 * 2, Screen.height / 100 * 59, Screen.width / 100 * 10, Screen.height / 100 * 10), button1Text, customGUI)) { GameObject mode = GameObject.FindGameObjectWithTag("GameController"); if (mode.GetComponent <Buy_Shoot_Modes> ().shootMode == true) { mode.GetComponent <Buy_Shoot_Modes> ().shootMode = false; mode.GetComponent <Buy_Shoot_Modes> ().buyMode = true; mode.GetComponent <Buy_Shoot_Modes> ().theWeapon = 1; whichinfo = 1; button1Text = "ATTACK MODE"; } else if (mode.GetComponent <Buy_Shoot_Modes> ().buyMode == true) { mode.GetComponent <Buy_Shoot_Modes> ().buyMode = false; mode.GetComponent <Buy_Shoot_Modes> ().shootMode = true; button1Text = "BUILD MODE"; whichinfo = 2; } } //SECONDARY BUTTONS GameObject mmode = GameObject.FindGameObjectWithTag("GameController"); Buy_Shoot_Modes sell = mmode.GetComponent <Buy_Shoot_Modes> (); if (sell.buyMode) { if (UnityEngine.GUI.Button(new Rect(Screen.width / 100 * 2, Screen.height / 100 * (float)98.5, Screen.width / 100 * 10, Screen.height / 100 * 5), button2Text, customGUI)) { GameObject mode = GameObject.FindGameObjectWithTag("GameController"); Buy_Shoot_Modes sel = mode.GetComponent <Buy_Shoot_Modes> (); if (sel.buyMode) { sel.theWeapon = 1; } whichinfo = 3; } if (!hardcore) { if (UnityEngine.GUI.Button(new Rect(Screen.width / 100 * (float)13.5, Screen.height / 100 * (float)98.5, Screen.width / 100 * 10, Screen.height / 100 * 5), button3Text, customGUI)) { GameObject mode = GameObject.FindGameObjectWithTag("GameController"); Buy_Shoot_Modes sel = mode.GetComponent <Buy_Shoot_Modes> (); if (sel.buyMode) { sel.theWeapon = 0; } whichinfo = 1; } if (UnityEngine.GUI.Button(new Rect(Screen.width / 100 * (float)25, Screen.height / 100 * (float)98.5, Screen.width / 100 * 10, Screen.height / 100 * 5), button4Text, customGUI)) { GameObject mode = GameObject.FindGameObjectWithTag("GameController"); Buy_Shoot_Modes sel = mode.GetComponent <Buy_Shoot_Modes> (); if (sel.buyMode) { sel.theWeapon = 2; } whichinfo = 4; } if (UnityEngine.GUI.Button(new Rect(Screen.width / 100 * (float)36.3, Screen.height / 100 * (float)98.5, Screen.width / 100 * (float)12, Screen.height / 100 * 5), button5Text, customGUI)) { GameObject mode = GameObject.FindGameObjectWithTag("GameController"); Buy_Shoot_Modes sel = mode.GetComponent <Buy_Shoot_Modes> (); if (sel.buyMode) { sel.theWeapon = 3; } whichinfo = 5; } } } else if (sell.shootMode) { /*if (UnityEngine.GUI.Button (new Rect (Screen.width / 100 * 13, Screen.height / 100 * 95, 105, 50), "grenade")) { * GameObject mode = GameObject.FindGameObjectWithTag ("GameController"); * Buy_Shoot_Modes sel = mode.GetComponent<Buy_Shoot_Modes> (); * if (sel.shootMode) * sel.theTowerWeapon = 1; * }*/ //UPGRADE BUTTON if (UnityEngine.GUI.Button(new Rect(Screen.width / 100 * (float)1.5, Screen.height / 100 * 99, Screen.width / 100 * 20, Screen.height / 100 * 5), "UPGRADE TOWER" + "\n Cost: " + GameObject.FindGameObjectWithTag("TheTower").GetComponent <TowerStats>().upgradeCost, customGUI)) { GameObject mode = GameObject.FindGameObjectWithTag("GameController"); Buy_Shoot_Modes sel = mode.GetComponent <Buy_Shoot_Modes> (); GameObject theT = GameObject.FindGameObjectWithTag("TheTower"); TowerStats ts = theT.GetComponent <TowerStats>(); int resources = ts.mResources; int cost = ts.upgradeCost; if ((resources - cost) >= 0) { ts.mResources -= cost; sel.upgradeTowerMult += 0.5f; theT.GetComponent <TowerStats>().upgradeCost += theT.GetComponent <TowerStats>().upgradeCost; } } /*if (UnityEngine.GUI.Button (new Rect (Screen.width / 100 * 35, Screen.height / 100 * 95, 105, 50), "laser")) { * GameObject mode = GameObject.FindGameObjectWithTag ("GameController"); * Buy_Shoot_Modes sel = mode.GetComponent<Buy_Shoot_Modes> (); * if (sel.shootMode) * sel.theTowerWeapon = 2; * }*/ } //GAME OVER BUTTON GameObject md = GameObject.FindGameObjectWithTag("GameController"); Buy_Shoot_Modes bsm = md.GetComponent <Buy_Shoot_Modes> (); //towerinfo GameObject tw = GameObject.FindGameObjectWithTag("TheTower"); if (bsm.gameover) { UnityEngine.GUI.Box(new Rect(Screen.width / 100 * 45, Screen.height / 100 * 30, Screen.width / 100 * 20, Screen.height / 100 * 20), "Survived " + (md.GetComponent <NewSpawnWaves>().waveCompleted + " Waves" + "\n\n" + "Score: " + tw.GetComponent <TowerStats>().mScore) , customGUI); if (UnityEngine.GUI.Button(new Rect(Screen.width / 100 * (float)47.5, Screen.height / 100 * 54, Screen.width / 100 * 15, Screen.height / 100 * 5), restart, customGUI)) { Application.LoadLevel(Application.loadedLevel); } if (UnityEngine.GUI.Button(new Rect(Screen.width / 100 * (float)50.5, Screen.height / 100 * 64, Screen.width / 100 * 10, Screen.height / 100 * 5), mainmenu, customGUI)) { Application.LoadLevel("StartMenu"); } } //WAVE ADVANCE BUTTON if (UnityEngine.GUI.Button(new Rect(Screen.width / 100 * (float)90.5, Screen.height / 100 * 42, Screen.width / 100 * 12, Screen.height / 100 * 5), "Advance Wave", customGUI)) { GameObject mode = GameObject.FindGameObjectWithTag("GameController"); NewSpawnWaves nsw = mode.GetComponent <NewSpawnWaves>(); nsw.advanceTheWave = true; } //INFO BOX UnityEngine.GUI.Box(new Rect(Screen.width / 100 * (float)0.5, Screen.height / 100 * 72, Screen.width / 100 * 30, Screen.height / 100 * 22), "", customGUI); GameObject tgc = GameObject.FindGameObjectWithTag("GameController"); Buy_Shoot_Modes ws = tgc.GetComponent <Buy_Shoot_Modes>(); float towerDamage = ws.towerWeapons[ws.theTowerWeapon].GetComponent <TowerAmmoStats>().mDamage; string towerType = ""; if (ws.theTowerWeapon == 0) { towerType = "Standard"; } else { towerType = "Splash"; } GameObject tsg = GameObject.FindGameObjectWithTag("TheTower"); TowerStats tss = tsg.GetComponent <TowerStats> (); switch (whichinfo) { case 0: //default tower stats theinfo = "" + "Tower Stats" + "\n\n" + "Damage" + "#x" + ": " + "#n" + towerDamage * ws.GetComponent <Buy_Shoot_Modes>().upgradeTowerMult + "\n" + "Type" + "#x" + ": " + "#n" + towerType + "\n" + "Fire Rate" + "#x" + ": " + "#n" + tw.GetComponent <TowerStats>().mFireRate + "\n"; //UnityEngine.GUI.Box (new Rect(Screen.width/100 * 2,Screen.height/100*75, 200, 100), "" ,customGUI); //FancyLabel( new Rect(Screen.width/100 * 2,Screen.height/100*75, Screen.width/100*20, Screen.height/100*10), theinfo, normal, bold, italic, TextAlignment.Left); //UnityEngine.GUI.Box (new Rect(Screen.width/100 * 2,Screen.height/100*75, 200, 100), "Info: Tower \n Damage: 100 \n Attack Speed: 0.5 \n Type: Normal" ); break; case 1: //Buy mode default turret. theinfo = "" + "Build Mode" + "#x" + ": " + "#n" + "Turret" + "\n\n" + "Type" + "#x" + ": " + "#n" + "Shotgun" + "\n" + "Damage" + "#x" + ": " + "#n" + "5" + "#x" + "/" + "#n" + "#FFDDDDFF" + "5" + "#!" + "#x" + "/" + "#n" + "#FF6666FF" + "5" + "\n" + "#!" + "Attack Speed" + "#x" + ": " + "#n" + "0.6" + "#x" + "/" + "#n" + "#FFDDDDFF" + "0.3" + "#!" + "#x" + "/" + "#n" + "#FF6666FF" + "0.1" + "\n" + "#!" + "Range" + "#x" + ": " + "#n" + "2" + "#x" + "/" + "#n" + "#FFDDDDFF" + "25" + "#!" + "#x" + "/" + "#n" + "#FF6666FF" + "30" + "\n" + "#!" + "Cost" + "#x" + ": " + "#n" + "400" + "#x" + "/" + "#n" + "#FFDDDDFF" + "600" + "#!" + "#x" + "/" + "#n" + "#FF6666FF" + "800" + "\n"; //UnityEngine.GUI.Box (new Rect(Screen.width/100 * 2,Screen.height/100*75, 200, 100),"" ,customGUI); //FancyLabel( new Rect(Screen.width/100 * 2,Screen.height/100*75, 200, 100), theinfo, normal, bold, italic, TextAlignment.Left); break; case 2: //Shoot mode default cannon theinfo = "" + "Tower Stats" + "\n\n" + "Damage" + "#x" + ": " + "#n" + towerDamage * ws.GetComponent <Buy_Shoot_Modes>().upgradeTowerMult + "\n" + "Type" + "#x" + ": " + "#n" + towerType + "\n" + "Fire Rate" + "#x" + ": " + "#n" + tw.GetComponent <TowerStats>().mFireRate + "\n"; // UnityEngine.GUI.Box (new Rect(Screen.width/100 * 2,Screen.height/100*75, 200, 100), "" ,customGUI); //FancyLabel( new Rect(Screen.width/100 * 2,Screen.height/100*75, 200, 100), theinfo, normal, bold, italic, TextAlignment.Left); break; case 3: //Buy mode wall theinfo = "" + "Build Mode" + "#x" + ": " + "#n" + "Wall" + "\n\n\n" + "Type" + "#x" + ": " + "#n" + "Unit Blocker" + "\n" + "Duration" + "#x" + ": " + "#n" + "3" + "#x" + "/" + "#n" + "#FFDDDDFF" + "5" + "#!" + "#x" + "/" + "#n" + "#FF6666FF" + "9" + "\n" + "#!" + "Cost" + "#x" + ": " + "#n" + "10" + "#x" + "/" + "#n" + "#FFDDDDFF" + "50" + "#!" + "#x" + "/" + "#n" + "#FF6666FF" + "90" + "\n"; //UnityEngine.GUI.Box (new Rect(Screen.width/100 * 2,Screen.height/100*75, 200, 100),"" ,customGUI); //FancyLabel( new Rect(Screen.width/100 * 2,Screen.height/100*75, 200, 100), theinfo, normal, bold, italic, TextAlignment.Left); break; case 4: //Buy mode slow theinfo = "" + "Build Mode" + "#x" + ": " + "#n" + "Slow Tower" + "\n\n" + "Type" + "#x" + ": " + "#n" + "Freeze Ray" + "\n" + "Damage" + "#x" + ": " + "#n" + "1" + "#x" + "/" + "#n" + "#FFDDDDFF" + "3" + "#!" + "#x" + "/" + "#n" + "#FF6666FF" + "5" + "\n" + "#!" + "Attack Speed" + "#x" + ": " + "#n" + "7" + "#x" + "/" + "#n" + "#FFDDDDFF" + "5" + "#!" + "#x" + "/" + "#n" + "#FF6666FF" + "3" + "\n" + "#!" + "Range" + "#x" + ": " + "#n" + "10" + "#x" + "/" + "#n" + "#FFDDDDFF" + "20" + "#!" + "#x" + "/" + "#n" + "#FF6666FF" + "30" + "\n" + "#!" + "Cost" + "#x" + ": " + "#n" + "300" + "#x" + "/" + "#n" + "#FFDDDDFF" + "550" + "#!" + "#x" + "/" + "#n" + "#FF6666FF" + "700" + "\n"; // UnityEngine.GUI.Box (new Rect(Screen.width/100 * 2,Screen.height/100*75, 200, 100),"" ,customGUI); //FancyLabel( new Rect(Screen.width/100 * 2,Screen.height/100*75, 200, 100), theinfo, normal, bold, italic, TextAlignment.Left); break; case 5: //Buy mode track theinfo = "" + "Build Mode" + "#x" + ": " + "#n" + "Launcher" + "\n\n" + "Type" + "#x" + ": " + "#n" + "Homing Missiles" + "\n" + "Damage" + "#x" + ": " + "#n" + "10" + "#x" + "/" + "#n" + "#FFDDDDFF" + "20" + "#!" + "#x" + "/" + "#n" + "#FF6666FF" + "40" + "\n" + "#!" + "Attack Speed" + "#x" + ": " + "#n" + "6" + "#x" + "/" + "#n" + "#FFDDDDFF" + "4" + "#!" + "#x" + "/" + "#n" + "#FF6666FF" + "3" + "\n" + "#!" + "Range" + "#x" + ": " + "#n" + "35" + "#x" + "/" + "#n" + "#FFDDDDFF" + "40" + "#!" + "#x" + "/" + "#n" + "#FF6666FF" + "50" + "\n" + "#!" + "Cost" + "#x" + ": " + "#n" + "500" + "#x" + "/" + "#n" + "#FFDDDDFF" + "900" + "#!" + "#x" + "/" + "#n" + "#FF6666FF" + "1100" + "\n"; // UnityEngine.GUI.Box (new Rect(Screen.width/100 * 2,Screen.height/100*75, 200, 100),"" ,customGUI); //FancyLabel( new Rect(Screen.width/100 * 2,Screen.height/100*75, 200, 100), theinfo, normal, bold, italic, TextAlignment.Left); break; case 6: break; } FancyLabel(new Rect(Screen.width / 100 * (float)2.5, Screen.height / 100 * 74, Screen.width / 100 * 30, Screen.height / 100 * 20), theinfo, normal, bold, italic, TextAlignment.Left); //FancyLabel( new Rect(Screen.width/100 * 2,Screen.height/100*75, 200, 100), theinfo, normal, bold, italic, TextAlignment.Center); //UnityEngine.GUI.Box (new Rect(Screen.width/100 * 2,Screen.height/100*75, 200, 100),""); }
// Update is called once per frame void Update() { if (thePathsHaveChanged) { thePathsHaveChanged = false; //thePathsHaveChanged = false; } //if(allPathsBlocked) //{ // allPathsBlocked = false; //} /* * if (Input.GetKey (KeyCode.B)) * { * buyMode = true; * shootMode = false; * } * * if(Input.GetKey(KeyCode.S)) * { * buyMode = false; * shootMode = true; * if(lastPlane) * { * lastPlane.renderer.material = oldMaterial; * lastPlane = null; * } * } */ /* * Ray ra = Camera.main.ScreenPointToRay(Input.mousePosition); * RaycastHit ht; * if(Physics.Raycast(ra,out ht,1000,buttonMask)) * { * if(lastButton) * lastButton.renderer.material = oldButton; * lastButton = ht.collider.gameObject; * lastButton.renderer.material = hoverMaterial; * * } * else * { * if(lastButton) * lastButton.renderer.material = oldButton; * lastButton = null; * } * if(Input.GetMouseButtonDown(0) && lastButton && lastButton.gameObject.tag == "SwitchMode") * { * shootMode = !shootMode; * buyMode = !buyMode; * lastButton.renderer.material = oldButton; * if(!buyMode) * { * if(lastPlane) * { * lastPlane.renderer.material = oldMaterial; * lastPlane = null; * } * } * Debug.Log("SWITCH"); * } * else if(Input.GetMouseButtonDown(0) && lastButton && buyMode) * { * theWeapon = (theWeapon+1) % weapons.Length; * lastButton.renderer.material = oldButton; * Debug.Log(theWeapon); * } */ if (gameover) { NewSpawnWaves sw = gameObject.GetComponent <NewSpawnWaves>(); sw.waveDuration = -1.0f; sw.numEnemiesRemaining = 1000; } if (buyMode && !gameover) { if (Input.GetMouseButton(0)) { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit, 1000, buyPlane)) { if (lastPlane) { lastPlane.renderer.material = oldMaterial; lastPlane.renderer.enabled = false; Destroy(hoverObject); } if (hit.collider.gameObject.tag != "Enemy") { lastPlane = hit.collider.gameObject; //oldMaterial = lastPlane.renderer.material; GridForUnits lsp = lastPlane.GetComponent <GridForUnits>(); if (lsp) { lastPlane.renderer.enabled = true; if (lsp.isAvailable) { int cstTBy = weapons[theWeapon].GetComponent <Weapons>().cost; GameObject towor = GameObject.FindGameObjectWithTag("TheTower"); int rsrce = towor.GetComponent <TowerStats>().mResources; if ((rsrce - cstTBy) >= 0) { lastPlane.renderer.material = hoverMaterial; } else { lastPlane.renderer.material = cantBuy; } } else { Weapons gtpgrd = lsp.whatsInside.GetComponent <Weapons>(); GameObject whtTpgrd = gtpgrd.upgradeIt; if (whtTpgrd != null) { int csy = whtTpgrd.GetComponent <Weapons>().cost; GameObject tweer = GameObject.FindGameObjectWithTag("TheTower"); int reesrc = tweer.GetComponent <TowerStats>().mResources; if (reesrc - csy >= 0) { lastPlane.renderer.material = hoverMaterial; } else { lastPlane.renderer.material = cantBuy; } } } if (lastPlane != null && lastPlane.GetComponent <GridForUnits>().whatsInside != null) { GameObject hoverUpgrade = lastPlane.GetComponent <GridForUnits>().whatsInside.GetComponent <Weapons>().upgradeDummy; if (hoverUpgrade) { hoverObject = (GameObject)Instantiate(hoverUpgrade, lastPlane.transform.position, Quaternion.identity); } } else { hoverObject = (GameObject)Instantiate(dummyWeapons[theWeapon], lastPlane.transform.position, Quaternion.identity); } } } else { //lastPlane.renderer.enabled = false; lastPlane = null; } } else { if (lastPlane) { lastPlane.renderer.material = oldMaterial; lastPlane.renderer.enabled = false; lastPlane = null; Destroy(hoverObject); } } } if (Input.GetMouseButtonUp(0) && lastPlane) { lastPlane.renderer.enabled = false; Destroy(hoverObject); Debug.Log("HELLO THERE"); grid = lastPlane.GetComponent <GridForUnits>(); if (grid.isAvailable) { if (weapons.Length > 0) { lastPlane.gameObject.tag = "Taken"; grid.isAvailable = false; //theTaken.gameObject.tag = "Taken"; dijkstraPath(start, dummyPaths); Debug.Log(allPathsBlocked); if (!allPathsBlocked) { //lastPlane.gameObject.tag = "NotTaken"; int costToBuy = weapons[theWeapon].GetComponent <Weapons>().cost; GameObject twr = GameObject.FindGameObjectWithTag("TheTower"); int resource = twr.GetComponent <TowerStats>().mResources; Debug.Log(resource); if ((resource - costToBuy) >= 0) { twr.GetComponent <TowerStats>().mResources -= costToBuy; Vector3 spawn = lastPlane.transform.position; GameObject currWeapon = (GameObject)Instantiate(weapons[theWeapon], spawn, Quaternion.identity); //temp.transform.localEulerAngles = new Vector3(0.0f, Random.Range(0,360), 0.0f); grid.whatsInside = currWeapon; grid.isAvailable = false; lastPlane.gameObject.tag = "Taken"; //wall specific placement; if (currWeapon.tag == "WallWeapon") { wallObjectSurvive wos = currWeapon.GetComponent <wallObjectSurvive>(); wos.planeItsOn = lastPlane.gameObject; } //GameObject start = GameObject.Find ("UnitsAllowedStart"); theTaken = lastPlane; theTaken.gameObject.tag = "Taken"; thePathsHaveChanged = true; if (thePath3.Contains(theTaken)) { thePath3 = dijkstraPath(start3, thePath3); //thePathsHaveChanged = true; //Debug.Log("Change Paths"); } if (thePath2.Contains(theTaken)) { thePath2 = dijkstraPath(start2, thePath2); //thePathsHaveChanged1 = true; } NewSpawnWaves nsw = gameObject.GetComponent <NewSpawnWaves>(); if (nsw.allBlue) { if (thePath.Contains(theTaken)) { thePath = dijkstraPath(start, thePath); //thePathsHaveChanged1 = true; } } } else { lastPlane.gameObject.tag = "NotTaken"; grid.isAvailable = true; } //thePathsHaveChanged = false; } else { lastPlane.gameObject.tag = "NotTaken"; grid.isAvailable = true; //theTaken.gameObject.tag = "NotTaken"; } } } else { if (grid.whatsInside != null) { GameObject gu = grid.whatsInside; Weapons getUpgrade = grid.whatsInside.GetComponent <Weapons>(); GameObject whatToUpgrade = getUpgrade.upgradeIt; if (whatToUpgrade != null) { int costToBuy = whatToUpgrade.GetComponent <Weapons>().cost; GameObject twr = GameObject.FindGameObjectWithTag("TheTower"); int resource = twr.GetComponent <TowerStats>().mResources; if (resource - costToBuy >= 0) { twr.GetComponent <TowerStats>().mResources -= costToBuy; Vector3 tempPos = lastPlane.transform.position; Quaternion tempRot = getUpgrade.transform.rotation; Destroy(gu); grid.whatsInside = null; GameObject currWeapon = (GameObject)Instantiate(whatToUpgrade, tempPos, tempRot); if (currWeapon.tag == "WallWeapon") { wallObjectSurvive wos = currWeapon.GetComponent <wallObjectSurvive>(); wos.planeItsOn = lastPlane; } grid.whatsInside = currWeapon; } } } } } } if (shootMode && !gameover) { GameObject theTower = GameObject.FindGameObjectWithTag("TheTower"); float fireRate = theTower.GetComponent <TowerStats>().mFireRate; float lastFired = theTower.GetComponent <TowerStats>().mLastFired; int playerHealth = theTower.GetComponent <TowerStats>().mHealth; if (Input.GetMouseButtonDown(0) && !mIsClickDown) { if (towerWeapons.Length > 0) { Debug.Log("In onDown"); mClickY = Input.mousePosition.y; mClickX = Input.mousePosition.x; mIsClickDown = true; Plane playerPlane = new Plane(Vector3.up, transform.position); Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); float hitdist; if (playerPlane.Raycast(ray, out hitdist)) { targetPosition = ray.GetPoint(hitdist); //Debug.Log(targetPosition); } } } else if (Input.GetMouseButtonUp(0) && Time.time - lastFired >= fireRate && playerHealth > 0 && theTowerWeapon < towerWeapons.Length - 1) { Debug.Log("In onUp"); mIsClickDown = false; mReleaseY = Input.mousePosition.y; /** Calculate the delta Y position of the mouse and get the angle */ float maxAngleScreenRatio = Screen.height / 2; float deltaY = mReleaseY - mClickY; if (deltaY > maxAngleScreenRatio) { deltaY = maxAngleScreenRatio; } else if (deltaY < -maxAngleScreenRatio) { deltaY = -maxAngleScreenRatio; } fireAngle = deltaY / maxAngleScreenRatio * MAX_FIRE_ANGLE; /** Get the tower */ if (!multiShot) { //towerAmmo = (GameObject)Instantiate(towerWeapons[theTowerWeapon], // TOWER_FIRE_VECTOR, // Quaternion.identity); //towerAmmo.GetComponent<TowerAmmoStats>().mDamage *= upgradeTowerMult; /** Create the cannon shot */ //FireTowersBasicAmmo cannon = towerAmmo.GetComponent<FireTowersBasicAmmo>(); //cannon.typeOfAmmo = theTowerWeapon; //cannon.radius *= theRadiusMult; //Vector3 dir = targetPosition - TOWER_FIRE_VECTOR; //cannon.dir = dir.normalized; //cannon.mAngle = fireAngle; spawnSpreadShots(numShots, targetPosition, fireAngle); } else { StartCoroutine(spawnMultiShots(3, targetPosition, fireAngle)); } theTower.GetComponent <TowerStats>().mLastFired = Time.time; } else if (Input.GetMouseButton(0) && theTowerWeapon == towerWeapons.Length - 1) { if (laserFireTime <= 0.0f) { //fire laser GameObject tmpAmmo = (GameObject)Instantiate(towerWeapons[theTowerWeapon], TOWER_FIRE_VECTOR, Quaternion.identity); tmpAmmo.transform.LookAt(targetPosition); laserFireTime = laserTime; } laserFireTime -= Time.deltaTime; if (towerWeapons.Length > 0) { mClickY = Input.mousePosition.y; Plane playerPlane = new Plane(Vector3.up, transform.position); Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); float hitdist; if (playerPlane.Raycast(ray, out hitdist)) { targetPosition = ray.GetPoint(hitdist); //Debug.Log(targetPosition); } } } else if (mIsClickDown && theTowerWeapon != towerWeapons.Length - 1) { //Plane playerPlane = new Plane(Vector3.up, transform.position); //Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); //float hitdist; //Vector3 newTarget = new Vector3(); //if(playerPlane.Raycast(ray, out hitdist)) //{ // newTarget = ray.GetPoint(hitdist); //} // float deltaX = targetPosition.x - newTarget.x; float deltaX = (mClickX - Input.mousePosition.x) / 4; float deltaZ = deltaX * Mathf.Acos(targetPosition.z / targetPosition.x); mClickX = Input.mousePosition.x; targetPosition.z -= deltaX; float maxAngleScreenRatio = Screen.height / 2; float deltaY = Input.mousePosition.y - mClickY; if (deltaY > maxAngleScreenRatio) { deltaY = maxAngleScreenRatio; } else if (deltaY < -maxAngleScreenRatio) { deltaY = -maxAngleScreenRatio; } fireAngle = deltaY / maxAngleScreenRatio * MAX_FIRE_ANGLE; //Debug.Log("Fire Angle: " + fireAngle); Vector3 dir = targetPosition - towerAmmoSpawn.position; dir = dir.normalized; dir.y += Mathf.Sin(fireAngle); dir = dir.normalized; float yAccel = FireTowersBasicAmmo.ACCEL_GRAVITY; float yVelocity = 2.0f * dir.y; float yPosInit = towerAmmoSpawn.position.y; //TOWER_FIRE_Y; float timeToHitPlus = (-yVelocity + Mathf.Sqrt(yVelocity * yVelocity - 4 * (yAccel / 2) * yPosInit)) / yAccel; float timeToHitMinus = (-yVelocity - Mathf.Sqrt(yVelocity * yVelocity - 4 * (yAccel / 2) * yPosInit)) / yAccel; float timeToHit = Mathf.Max(timeToHitPlus, timeToHitMinus) / 90.0f; //Debug.Log( "Time to hit (max): " + timeToHit); Vector3 hitLocation = new Vector3(towerAmmoSpawn.position.x + dir.x * timeToHit * 100.0f, 0, towerAmmoSpawn.position.z + dir.z * timeToHit * 100.0f); //Debug.Log ("x, y, z: " + hitLocation.x + ", " + hitLocation.y + ", " + hitLocation.z); Destroy(mTargetLocation); Destroy(mTargetPole); Destroy(mTargetLine); mTargetLocation = GameObject.CreatePrimitive(PrimitiveType.Sphere); mTargetLocation.renderer.material = mTargetMaterial; // mTargetPole = GameObject.CreatePrimitive(PrimitiveType.Cylinder); mTargetLine = GameObject.CreatePrimitive(PrimitiveType.Cylinder); Destroy(mTargetLine.collider); float hitDistX = Mathf.Abs(hitLocation.x - towerAmmoSpawn.position.x); float hitDistZ = Mathf.Abs(hitLocation.z - towerAmmoSpawn.position.z); float totalHitDist = Mathf.Sqrt(hitDistX * hitDistX + hitDistZ * hitDistZ); float angle = Mathf.Atan(hitDistZ / hitDistX); //mTargetPole.transform.localScale = new Vector3(2, Mathf.Tan(fireAngle) * hitDistX / 4, 2); //float poleDistX = Mathf.Cos(angle) * totalHitDist / 2; //float poleDistZ = Mathf.Sin(angle) * totalHitDist / 2; //float poleX = towerAmmoSpawn.position.x + poleDistX; //float poleZ = towerAmmoSpawn.position.z + poleDistZ; //if (hitLocation.z < 0) { // poleZ = -poleZ; //} //Vector3 halfWay = new Vector3(poleX, 0, poleZ); //mTargetPole.transform.position = halfWay; Vector3 lineLocation = TOWER_FIRE_VECTOR; mTargetLine.renderer.material.color = new Color32(255, 0, 0, 0); lineLocation.x = towerAmmoSpawn.position.x; lineLocation.y = 0; lineLocation.z = towerAmmoSpawn.position.z; if (hitLocation.z > 0) { angle = -angle; } mTargetLine.transform.localScale = new Vector3(400, 0.25f, 0.25f); mTargetLine.transform.position = lineLocation; mTargetLine.transform.RotateAround(Vector3.zero, Vector3.up, Mathf.Rad2Deg * angle); mTargetLine.transform.position = lineLocation; mTargetLocation.transform.localScale = new Vector3(5, 5, 5); mTargetLocation.transform.position = hitLocation; } } }