void Update() { if (m_mode.PlayerMode == GameMode.Mode.PLAYER_PLAYER || (m_turnManager.m_playerTurn.PlayerTag == Unit.PlayerTag.PLAYER_1)) { Vector2 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition); m_selectionEnd = mousePos; if (Input.GetMouseButtonDown(0)) { m_selectionStart = mousePos; if (!m_timer.Paused) { bool selectedAUnit = false; foreach (Unit unit in m_units) { if (Intersects(unit) && m_turnManager.m_playerTurn.PlayerTag == unit.m_playerTag) { m_selectedUnits.Add(unit); unit.Select(); selectedAUnit = true; } } if (!selectedAUnit) { DeSelectEverything(); } } } else if (Input.GetMouseButtonUp(0) && !m_timer.Paused) { float selectionMinX = m_selectionStart.x < m_selectionEnd.x ? m_selectionStart.x : m_selectionEnd.x; float selectionMaxX = m_selectionStart.x < m_selectionEnd.x ? m_selectionEnd.x : m_selectionStart.x; float selectionMinY = m_selectionStart.y < m_selectionEnd.y ? m_selectionStart.y : m_selectionEnd.y; float selectionMaxY = m_selectionStart.y < m_selectionEnd.y ? m_selectionEnd.y : m_selectionStart.y; foreach (Unit unit in m_units) { if (unit.m_playerTag == m_turnManager.m_playerTurn.PlayerTag) { if (UnitWithinSelection(unit, selectionMinX, selectionMaxX, selectionMinY, selectionMaxY)) { unit.Select(); m_selectedUnits.Add(unit); } } } m_selectionEnd = m_selectionStart; } else if (Input.GetMouseButtonDown(1) && !m_timer.Paused) { Unit target = null; foreach (Unit unit in m_units) { if (unit.m_playerTag != m_turnManager.m_playerTurn.PlayerTag) { if (Intersects(unit)) { target = unit; } } } if (m_selectedUnits.Count > 0) { for (int i = 0; i < m_selectedUnits.Count; ++i) { if (target == null) { m_selectedUnits[i].SetTargetPosition(LimitMove(mousePos)); } else { m_selectedUnits[i].SetNearestTarget(target); } } } } DrawSelection(); } else { BlueSelector(false); RedSelector(false); if (!m_timer.Paused) { m_decisionTime += Time.deltaTime; if (m_decisionTime >= m_decisionRate) { m_decisionTime = 0.0f; Player computer = m_turnManager.m_playerTurn; List <Unit> friendlies = GetFriendlies(computer.PlayerTag); int min = 0; int max = 5; if (computer.Crystals < 50 || computer.Crystals < m_budget) { min++; } if (friendlies.Count <= 0) { max--; } int decision = Random.Range(min, max); if (decision == 0) { int range = 3; if (computer.Crystals < 150) { range--; } if (computer.Crystals < 100) { range--; } if (computer.Crystals < 50) { range--; } if (range >= 1) { int x = Random.Range(0, range); if (x == 0) { m_spawner.Purchase(Unit.UnitType.ARCHER); } if (x == 1) { m_spawner.Purchase(Unit.UnitType.CATAPULT); } if (x == 2) { m_spawner.Purchase(Unit.UnitType.DRAGON); } } m_budget = Random.Range(50, 250); m_decisionRate = 1.0f; } else if (decision >= 1 && decision <= 3) { computer.Crystals += 5; m_decisionRate = 0.2f; } else { m_decisionRate = 1.0f; int y = Random.Range(0, friendlies.Count); Unit chosen = friendlies[y]; Vector2 targetPosition = Random.insideUnitCircle.normalized * 10.0f; targetPosition = LimitMove(targetPosition); chosen.SetTargetPosition(targetPosition); } } } } }