void Update() { trailRenderer = GetComponent <TrailRenderer>(); numPositions = trailRenderer.GetPositions(TrailRecord); numLines = numPositions - 1; for (int i = 0; i < numPositions; i++) { TrailRecord[i].y = 0.0f; } if (isLineCollide()) { Enemylist = GameObject.FindGameObjectsWithTag("Enemy"); Woodlist = GameObject.FindGameObjectsWithTag("Wood"); Stonelist = GameObject.FindGameObjectsWithTag("Stone"); foreach (GameObject Enemy in Enemylist) { if (Enemy.name == "micro_dragon_fino(Clone)") { //Debug.Log("I dont want dino to die!"); continue; } check = true; transform = Enemy.GetComponent <Transform>(); myLine currentLine; currentLine.S = transform.position; currentLine.E = Centor; for (int i = CircleStart + 1; i < numLines - 1; i++) { if (isLinesIntersect(lines[i], currentLine)) { check = false; break; } } if (check) { //Debug.Log("Destroy Enemy"); //EffectManager.Instance.SplashEffect(Enemy.transform.position, Vector3.up, null, // EffectManager.EffectType.Splash); Instantiate(SplashEffect, Enemy.transform.position, Quaternion.LookRotation(Vector3.up)); audioPlayer.PlayOneShot(useClip); Destroy(Enemy); } } foreach (GameObject Wood in Woodlist) { check = true; transform = Wood.GetComponent <Transform>(); myLine currentLine; currentLine.S = transform.position; currentLine.E = Centor; for (int i = CircleStart + 1; i < numLines - 1; i++) { if (isLinesIntersect(lines[i], currentLine)) { check = false; break; } } if (check) { playerResource.GetWood(resourceNumWood); uiManager.UpdateWood(); Destroy(Wood); } } foreach (GameObject Stone in Stonelist) { check = true; transform = Stone.GetComponent <Transform>(); myLine currentLine; currentLine.S = transform.position; currentLine.E = Centor; for (int i = CircleStart + 1; i < numLines - 1; i++) { if (isLinesIntersect(lines[i], currentLine)) { check = false; break; } } if (check) { playerResource.GetStone(resourceNumStone); uiManager.UpdateStone(); Destroy(Stone); } } } }
// Update is called once per frame void Update() { if (!isBuild) { isBuild = Input.GetKey(KeyCode.B); if (isBuild) { Instantiate(Area, new Vector3(0.0f, 0.1f, 0.0f), Quaternion.identity); } } else { if (!(Input.GetKey(KeyCode.Alpha1) || Input.GetKey(KeyCode.Keypad1) || Input.GetKey(KeyCode.Alpha2) || Input.GetKey(KeyCode.Keypad2))) { GetNumber = true; } if ((Input.GetKey(KeyCode.Alpha1) || Input.GetKey(KeyCode.Keypad1)) && GetNumber) { ray = FollowCam.ScreenPointToRay(Input.mousePosition); mousePos.x = ray.origin.x + ray.direction.x * (-ray.origin.y / ray.direction.y); mousePos.z = ray.origin.z + ray.direction.z * (-ray.origin.y / ray.direction.y); mousePos.y = 0.0f; Debug.Log(mousePos); if (Mathf.Pow(mousePos.x, 2.0f) + Mathf.Pow(mousePos.z, 2.0f) < Mathf.Pow(AreaSize, 2.0f)) { if (playerResource.wood > 0 && playerResource.stone > 0) { playerResource.GetWood(-1); playerResource.GetStone(-1); uiManager.UpdateWood(); uiManager.UpdateStone(); Instantiate(ArcherTower, mousePos, ArcherRotation); } } GetNumber = false; } else if ((Input.GetKey(KeyCode.Alpha2) || Input.GetKey(KeyCode.Keypad2)) && GetNumber) { ray = FollowCam.ScreenPointToRay(Input.mousePosition); mousePos.x = ray.origin.x + ray.direction.x * (-ray.origin.y / ray.direction.y); mousePos.z = ray.origin.z + ray.direction.z * (-ray.origin.y / ray.direction.y); mousePos.y = 0.0f; Debug.Log(mousePos); if (Mathf.Pow(mousePos.x, 2.0f) + Mathf.Pow(mousePos.z, 2.0f) < Mathf.Pow(AreaSize, 2.0f)) { if (playerResource.wood > 1 && playerResource.stone > 0) { playerResource.GetWood(-2); playerResource.GetStone(-1); uiManager.UpdateWood(); uiManager.UpdateStone(); Instantiate(CanonTower, mousePos, Quaternion.identity); } } GetNumber = false; } } if (Input.GetKey(KeyCode.Escape)) { Destroy(GameObject.Find("Area(Clone)")); isBuild = false; } }