// Lifecycle private void LifecycleTick(object sender, EventArgs e) { if (this.Alive) { // Motion this.CurrentDirection = this.NextDirection; this.Move(); // Check food collision if (this.DoesCollideWith(this.CurrentPlayer.Food)) { this.CurrentPlayer.Food.Relocate(); this.FoodEatenCount++; SnakeAteFood.Fire(this.CurrentPlayer); } else if (this.DoesCollideWith(this.EnemyPlayer.Food)) { this.EnemyPlayer.Food.Relocate(); this.ShortenSnake(1 + 1 /* <-- move compensation */); } else { this.ShortenSnake(0 + 1 /* <-- move compensation */); } // Check player collision if (DoesCollideWithOneOf(this.Segments.SkipWhile(segment => segment == this.Segments[0]))) { this.ShortenSnake(this.Segments.Count - this.Segments.FindLastIndex(DoesCollideWith)); } else if (DoesCollideWith(this.EnemyPlayer.Snake)) { SnakeDie.Fire(this.CurrentPlayer); } } }
private void Start() { sd = GameObject.FindGameObjectWithTag("Snake").GetComponent <SnakeDie>(); }