// Update is called once per frame void Update() { if (needsToGetNewTarget) { // Find new target //target = hexagonManager.GetBestHexagonDistanceScaled(computer.GetComponent<ComputerMesh>().GetCurAngle()); target = hexagonManager.GetBestHexagonPeriod(); Vector2 shootingData = target.GetShootingAngle(computer.GetComponent <ComputerMesh>().GetCurAngle()); moveToAngle = shootingData[0]; shootAtAngle = shootingData[1]; // Tell ComputerMesh to move there computer.GetComponent <ComputerMesh>().SetTargetAngle(moveToAngle); Debug.Log("Moving to angle " + moveToAngle.ToString() + ", shooting at number " + target.GetNumber()); needsToGetNewTarget = false; isMoving = true; } if (!isMoving && !missileIsActive && !needsToGetNewTarget) { FireMissile(); missileIsActive = true; isMoving = false; needsToGetNewTarget = true; } // Check if missile is too far away if (missile && Vector2.Distance(missile.transform.position, Vector2.zero) > trackRadius + 1) { Destroy(missile); missileIsActive = false; needsToGetNewTarget = true; } }