private void OnTriggerEnter2D(Collider2D collision) { if (collision.name.Equals("Snake")) { Destroy(gameObject); OnFoodEaten?.Invoke(); } }
private void OnTriggerEnter(Collider other) { if (!other.CompareTag("Snake")) { return; } OnFoodEaten?.Invoke(); Destroy(gameObject); }
private void OnTriggerEnter(Collider other) { InterarctionType it; if (_npc && _npc.AllowedToInteract(other.gameObject, out it)) { if (it == InterarctionType.Food) { OnFoodEaten?.Invoke(); } } }
public void Update(Food food) { // Snake head move SnakeHead.Move(); SnakeHead.Update(); //Snake bodypart move Direction previousDirection; Direction nextDirection = SnakeHead.Direction; foreach (var part in SnakeBody) { part.Move(); part.Update(); previousDirection = part.Direction; part.Direction = nextDirection; nextDirection = previousDirection; } //check if snake head hit wall if (SnakeHead.HitWall()) { OnHitWall?.Invoke(); } //check if snake eat food if (SnakeHead.EatenFood(food)) { OnFoodEaten?.Invoke(); AddSnakeBody(); } //check if snakehead hit body foreach (var part in SnakeBody) { if (SnakeHead.X == part.X && SnakeHead.Y == part.Y) { OnHitBody?.Invoke(); } } IsUpdating = false; }
private void CheckIfItemIsFood() { // If the selected item is null or is not of the category food, drop the item and reset timer values if (m_SelectedSlot.ObjectData == null || m_SelectedSlot.ObjectData.ItemCategory != "Food") { ResetDropKey(); DropItem(m_SelectedSlot); } else { m_HoldingDropKeyTime -= Time.deltaTime; // When the timer is below 0, set the key back to not being pressed, gain the health value and remove the item if (m_HoldingDropKeyTime < 0f) { ResetDropKey(); OnFoodEaten?.Invoke(m_SelectedSlot.ObjectData); RemoveSingleItem(m_SelectedSlot); } } }
public override void Remove() { OnFoodEaten?.Invoke(this, new FoodEatenEventArgs(this)); base.Remove(); }