bool InArea() { Vector3 mp = new Vector3(Input.mousePosition.x, Input.mousePosition.y, Camera.main.nearClipPlane); Vector3 sq = Camera.main.WorldToScreenPoint(this.square.transform.position); Vector3 sq0 = new Vector3(sq.x - x, sq.y - y, sq.z); Vector3 sq2 = new Vector3(sq.x + x, sq.y + y, sq.z); int Hieght = (int)(sq0.y - sq2.y); int width = (int)(sq0.x - sq2.y); //Debug.Log(""); //Debug.Log(""); //Debug.Log("Mouse position is x: " + mp.x + " Y: " + mp.y); //Debug.Log("Square position is x: " + sq.x + " Y: " + sq.y); //Debug.Log("Square position is x: " + sq2.x + " Y: " + sq2.y); //Debug.Log(""); //float angle = Mathf.Atan2(sq.y - mp.y, mp.x - sq.x) * Mathf.Rad2Deg; if ((mp.x > sq0.x && mp.x < sq2.x) && (mp.y > sq0.y && mp.y < sq2.y)) { // Debug.Log("in the Area"); StaticClasses.toggleTower(this.TowerNum); //Debug.Log("Instantiating..."+StaticClasses.isActive1); } return(false); }
void onTower1() { if (!StaticClasses.getActive(towerNum) && StaticClasses.Score >= 100) { Debug.Log("Click 1"); StaticClasses.towers[towerNum - 1] = GameObject.Instantiate(tower1Pre); StaticClasses.towers[towerNum - 1].transform.position = new Vector3(this.cube.transform.position.x, this.cube.transform.position.y, this.cube.transform.position.z); StaticClasses.toggleActive(this.towerNum); StaticClasses.toggleTower(towerNum); StaticClasses.Score -= 100; TowerHealth.towerHealth[towerNum - 1].gameObject.SetActive(true); } }
// Update is called once per frame void Update() { int i; for (i = 0; i < 4; i++) { towerHealth[i].value = StaticClasses.newTowerLife[i]; if (towerHealth[i].value <= 0) { Destroy(StaticClasses.towers[i]); StaticClasses.toggleActive(i + 1); StaticClasses.newTowerLife[i] = 100; towerHealth[i].value = 100; towerHealth[i].gameObject.SetActive(false); StaticClasses.toggleTower(i + 1); //kill tower Debug.Log("temp"); } } }