void Update() { Selected = GM.GetSelectedUnit(); Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit, 20)) { if (hit.transform.CompareTag("Tile")) { Tile = hit.transform.gameObject; } else { Tile = null; } } if (Input.GetMouseButtonDown(0) && Tile != null) { TileTaken TakenObj = Tile.GetComponent <TileTaken>(); if (!TakenObj.IsTaken && GM.GetGems() >= Prices[Selected]) { GM.ChangeGems(-Prices[Selected]); Vector3 pos = new Vector3(Tile.transform.position.x + AllUnits[Selected].transform.position.x, Tile.transform.position.y + AllUnits[Selected].transform.position.y, -1f); TakenObj.CurrentUnit = Instantiate(AllUnits[Selected], pos, Quaternion.identity); TakenObj.IsTaken = true; } } }
// Update is called once per frame void Update() { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit, 1000)) { if (hit.transform.tag == "Tile") { Tile = hit.transform.gameObject; } else { Tile = null; } } if (Input.GetMouseButtonDown(0) && Tile != null) { TileTaken tscr = Tile.GetComponent <TileTaken>(); if (!tscr.isTaken && mscr.money >= (int)prices[Selected]) { mscr.money -= (int)prices[Selected]; Vector3 pos = new Vector3(Tile.transform.position.x, 50, Tile.transform.position.z); tscr.Tower = (GameObject)Instantiate(towers[Selected], pos, Quaternion.identity); GameObject go = Instantiate(effect) as GameObject; go.transform.position = pos; tscr.isTaken = true; Selected = 50; } } }
// Update is called once per frame void Update() { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit, 20)) { if (hit.transform.tag == "Tile") { this.tile = hit.transform.gameObject; } else { this.tile = null; } } if (Input.GetMouseButtonDown(0) && this.tile != null) { TileTaken tileTakenScript = this.tile.GetComponent <TileTaken> (); if (!tileTakenScript.isTaken && (this.moneyScript.money - prices[this.selected]) >= 0) { this.moneyScript.money -= prices[this.selected]; Vector3 pos = new Vector3(this.tile.transform.position.x, 1f, this.tile.transform.position.z); tileTakenScript.tower = (GameObject)Instantiate(towers[this.selected], pos, Quaternion.identity); tileTakenScript.isTaken = true; } } }
// Update is called once per frame void Update() { Vector2 ray = Camera.main.ScreenToWorldPoint(Input.mousePosition); RaycastHit2D hit = Physics2D.Raycast(ray, Vector2.zero, 20); if (hit) { if (hit.transform.tag == "Tile") { tile = hit.transform.gameObject; } else { tile = null; } if (Input.GetMouseButtonDown(0) && tile != null) { TileTaken tileScript = tile.GetComponent <TileTaken>(); if (!tileScript.isTaken && moneyScript.money >= prices[selected]) { //moneyScript.money -= prices[selected]; Vector2 pos = new Vector2(tile.transform.position.x, tile.transform.position.y); //tileScript.tower = (GameObject)Instantiate(towers[selected], pos, Quaternion.identity); //tileScript.isTaken = true; } } } }
// Update is called once per frame void Update() { if (this.lost) { this.lost = false; this.waveManagerScript.numberOut = 0; this.waveManagerScript.ResetCooldown(); GameObject[] towers = GameObject.FindGameObjectsWithTag("Tower"); GameObject[] enemies = GameObject.FindGameObjectsWithTag("Enemy"); for (int i = 0; i < towers.Length; i++) { Destroy(towers [i]); } for (int i = 0; i < enemies.Length; i++) { Destroy(enemies [i]); } GameObject[] tiles = GameObject.FindGameObjectsWithTag("Tile"); for (int i = 0; i < tiles.Length; i++) { TileTaken tileTakenScript = tiles [i].GetComponent <TileTaken> (); tileTakenScript.isTaken = false; } GameObject[] projectiles = GameObject.FindGameObjectsWithTag("Projectile"); for (int i = 0; i < projectiles.Length; i++) { Destroy(projectiles [i]); } this.moneyScript.money = this.initMoney; } }
// Update is called once per frame void Update() { //create out camera ray Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit, 20)) { //check if what we hit has a tag named Path //Debug.Log(hit.transform.tag); if (hit.transform.tag == "Path") { Path = hit.transform.gameObject; } else { Path = null; } } if (Input.GetMouseButtonDown(0) && Path != null) { //get access to the TileTaken script for the Path hit by ray cast TileTaken tileTakenScript = Path.GetComponent <TileTaken>(); if (!tileTakenScript.isTaken) { //do costing / money adjustments //get a position based on the Path we hit Vector3 pos = new Vector3(Path.transform.position.x, Path.transform.position.y, -1f); tileTakenScript.Tower = (GameObject)Instantiate(towers[selected], pos, Quaternion.identity); tileTakenScript.isTaken = true; } } }
// Update is called once per frame void Update() { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit)) { if (hit.transform.tag == "tile") { Debug.Log(hit.collider.name); Tile = hit.transform.gameObject; } else { Tile = null; } } if (Input.GetMouseButtonDown(0) && Tile != null) { TileTaken tscr = Tile.GetComponent <TileTaken>(); if (!tscr.isTaken && mscr.money > prices[Selected]) { mscr.money -= prices[Selected]; Vector3 pos = new Vector3(Tile.transform.position.x, (Tile.transform.position.y) + 3F, Tile.transform.position.z); tscr.Tower = (GameObject)Instantiate(towers[Selected], pos, Quaternion.identity); tscr.isTaken = true; } } }
// Update is called once per frame void Update() { timeTillPlant -= Time.deltaTime; timeSlider.value = timeTillPlant / minPlantDelay; Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);//kamerayı yaratılan dünyada screen pointe dönüştürüyoruz RaycastHit hit; if (Physics.Raycast(ray, out hit, 20)) { if (hit.transform.tag == "tile") //eğer tıklanan yer tile a eşit ise { Tile = hit.transform.gameObject; //basılan yere towerı koy } if ((Input.GetMouseButtonDown(1) && Tile != null)) { if (hit.collider.tag == "tower") { TileTaken tilescript = Tile.GetComponent <TileTaken>(); Destroy(hit.collider.gameObject); TileTakensSetFalse(); } } } else { Tile = null;//eğer tile değilse temizle ki boş yere tower koyulamasın } if (Input.GetMouseButtonDown(0) && Tile != null)//mouse sol tuşuna basılmışsa ve tile ise { TileTaken tilescript = Tile.GetComponent <TileTaken>(); //tower ve isTaken için generic obje olusturuyoruz ve onlara ulaşmak isitoyurz if (!tilescript.isTaken && moneyscript.money >= (int)prices[Selected])//tile alınmamış ise ve seçilen tower modeli sahip olduğumuz paradan yüksek değilse { if (timeTillPlant <= 0) { //tower fiyatını sahip olduğumuz paradan çıkar moneyscript.money -= (int)prices[Selected]; Vector3 pos = new Vector3(Tile.transform.position.x, 2F, Tile.transform.position.z); //koymamız gereken tile a tam ortasına gelebilmesi için x ve z yi ortadan alıcak y yi biraz daha yukarısından alıcak tileın tilescript.Tower = (GameObject)Instantiate(towers[Selected], pos, Quaternion.identity); //daha sonra tile a koyulan toweri silmek için kullanacağım TileTakensSetTrue(); //towerin bulunduğu yeri true yaparsak tekrar üstüne konulmasını engellemiş oluruz timeTillPlant = minPlantDelay; } } } }
// Update is called once per frame void Update() { if (lost) { wavscr.NumOut = 0; wavscr.resetcd(); GameObject[] towers = GameObject.FindGameObjectsWithTag("Tower"); GameObject[] tiles = GameObject.FindGameObjectsWithTag("Tile"); GameObject[] enemies = GameObject.FindGameObjectsWithTag("Enemy"); GameObject[] projs = GameObject.FindGameObjectsWithTag("projectile"); for (int i = 0; i < towers.Length; i++) { Destroy(towers[i]); } for (int y = 0; y < enemies.Length; y++) { Destroy(enemies[y]); } for (int z = 0; z < tiles.Length; z++) { TileTaken tscr = tiles[z].GetComponent <TileTaken>(); tscr.isTaken = false; } for (int a = 0; a < projs.Length; a++) { Destroy(projs[a]); } if (!alreadydonethat) { pontuacao = wavscr.pontos; energia = mscr.money; alreadydonethat = true; } final.color = new Color(255, 255, 255, 255); final.text = "You Lose\n The mosquitoes entered your house\n Final Score: \n Enemies killed: " + pontuacao + "\nEnergy: " + energia; } }
// Update is called once per frame void Update() { if (lost) { lost = false; wavemanagerscript.NumOut = 0; wavemanagerscript.resetcd(); GameObject[] towers = GameObject.FindGameObjectsWithTag("tower"); GameObject[] enemies = GameObject.FindGameObjectsWithTag("enemy"); for (int i = 0; i < towers.Length; i++) { Destroy(towers[i]); } for (int j = 0; j < enemies.Length; j++) { Destroy(enemies[j]); } GameObject[] tiles = GameObject.FindGameObjectsWithTag("tile"); for (int n = 0; n < tiles.Length; n++) { TileTaken tilescript = tiles[n].GetComponent <TileTaken>(); tilescript.isTaken = false; } GameObject[] projecitles = GameObject.FindGameObjectsWithTag("projectile"); for (int k = 0; k < projecitles.Length; k++) { Destroy(projecitles[k]); } GameObject[] houseptorectors = GameObject.FindGameObjectsWithTag("houseprotecter"); for (int a = 0; a < houseptorectors.Length; a++) { Destroy(houseptorectors[a]); } moneyscript.money = initmoney; InitiateTowerPotector(); } }
public void TileTakensSetTrue() { TileTaken tilescript = Tile.GetComponent <TileTaken>(); tilescript.isTaken = true; }
public void TileTakensSetFalse() { TileTaken tilescript = Tile.GetComponent <TileTaken>(); tilescript.isTaken = false; }
// Use this for initialization void Start() { moneyscript = GameObject.Find("GameLogic").GetComponent <Money>(); tilescript = Tile.GetComponent <TileTaken>(); }