private void SpawnItem(Unit collector) { CollectedItem item = Instantiate(itemPrefab); item.transform.position = transform.position; item.Initialize(itemData.sprite, itemSpawnYCurve); ItemCollected?.Invoke(itemData); if (_curContent <= 0 && !_unit.IsDying) { _unit.Kill(collector); // todo: animate destruction } }
protected void OnTriggerEnter2D(Collider2D collision) { if (_collected) { return; } //if the player touches me, I am collected PlayerController player = collision.gameObject.GetComponent <PlayerController>(); if (player != null) { _collected = true; ItemCollected?.Invoke(this); OnCollected(); } }
private void OnCollisionEnter2D(Collision2D collision) { if (!collision.gameObject.TryGetComponent <Platform>(out Platform platform)) { Physics2D.IgnoreCollision(collision.collider, GetComponent <Collider2D>()); } else { GetComponent <Rigidbody2D>().bodyType = RigidbodyType2D.Kinematic; GetComponent <Rigidbody2D>().velocity = Vector2.zero; } if (collision.gameObject.TryGetComponent <King>(out King king)) { ChargeItem(king, 1); ItemCollected?.Invoke(); } }
/// <summary> /// Pick up Item /// Although the inventory is limited to 1 item, the game could be extended to allow multiple persistent /// items (Fuel) or consumables to be collected. /// </summary> /// <param name="other">Unity Component</param> private void Collect(Component other) { if (inventory.Count > 0 || !CanCollect || gameOver) { return; } var collectableItem = other.gameObject.GetComponent <ICollectable>(); if (collectableItem == null) { return; } HasItems = true; inventory.Add(other.transform); collectableItem.Collect(transform); ItemCollected?.Invoke(); }
void RpcItemCollected(Item.VegetableType itemType) { ItemCollected?.Invoke(itemType); }