private void OnTriggerExit2D(Collider2D other) { if (other.gameObject.CompareTag(tagsFurniture)) { int idFurniture = other.gameObject.GetComponent <IFurniture>().GetID(); int findIndex = furnitures.Select((item, index) => new { Item = item, Index = index }) .First(i => { IFurniture furni = i.Item.GetComponent <IFurniture>(); return(furni.GetID() == idFurniture); }) .Index; furnitures.RemoveAt(findIndex); } if (other.gameObject.CompareTag(tagsMobs)) { int idmobs = other.gameObject.GetComponent <IMob>().GetID(); int findIndex = mobs.Select((item, index) => new { Item = item, Index = index }) .First(i => { IMob mobs = i.Item.GetComponent <IMob>(); if (mobs != null) { return(mobs.GetID() == idmobs); } return(false); }) .Index; mobs.RemoveAt(findIndex); } }
private void Update() { if (furnitures.Count > 0) { if (selectedFurniture != null) { int idSelectedFurniture = selectedFurniture.GetComponent <IFurniture>().GetID(); foreach (GameObject item in furnitures) { IFurniture _furniture = item.GetComponent <IFurniture>(); if (_furniture.GetID() != idSelectedFurniture) { _furniture.NoneSelected(); } else { _furniture.Selected(); } } } selectedFurniture = furnitures .OrderBy(i => Vector2.Distance(transform.position, i.transform.position)) .First(); } }
private void OnTriggerExit2D(Collider2D other) { try { if (other.gameObject.CompareTag(tagsFurniture)) { int idFurniture = other.gameObject.GetComponent <IFurniture>().GetID(); var findIndex = furnitures.Select((item, index) => new { Item = item, Index = index }) .First(i => { IFurniture furni = i.Item.GetComponent <IFurniture>(); return(furni.GetID() == idFurniture); }); if (findIndex != null) { furnitures.RemoveAt(findIndex.Index); } } } catch (Exception e) { } }