public IEnumerator checkNear() { while (true) { // Console.WriteLine("Checking nearby"); foreach (var goThing in Game.getAll()) { if (this != goThing && goThing is BasicUnit go) { var xdiff = go.position.x - this.position.x; var ydiff = go.position.y - this.position.y; var diff = (Math.Pow(xdiff, 2) + Math.Pow(ydiff, 2)); var dis = Math.Sqrt(diff); if (dis < 10) { Console.WriteLine("FOUND ENEMY "); target = go; yield break; } else { // Console.WriteLine("Checking nearby NOTFOUND"); } } } yield return(null); } }
public IEnumerator fight(BasicUnit target) { while (target.health.health > 0) { yield return(null); Console.WriteLine("fighting eachother"); target.health.health -= new Random().Next(20); } }