// Use this for initialization void Start() { Transform[] children = this.GetComponentsInChildren <Transform> (); int count = 0; for (int i = 0; i < children.Length; ++i) { if (children[i].name == "Fish") { ++count; } } fish = new FishAgent[count]; count = 0; foreach (Transform child in children) { if (child.name == "Fish") { fish[count++] = new FishAgent(child); } if (count == fish.Length) { break; } } }
// Poisson représenté par un trait de 10px partant de la tête du poisson et allant vers sa queue dont les coordonnées sont calculées à partir de la direction du poisson (et donc sa vitesse en x et en y). private void DrawFish(FishAgent _fish) { Line body = new Line(); body.Stroke = Brushes.Black; body.X1 = _fish.PosX; body.Y1 = _fish.PosY; body.X2 = _fish.PosX - 10 * _fish.SpeedX; body.Y2 = _fish.PosY - 10 * _fish.SpeedY; oceanCanvas.Children.Add(body); }