private bool CheckUnlockDoor(Direction dir) { RaycastHit2D rh; Vector3 rcDir = Vector3.zero; switch (dir) { case Direction.right: rcDir = Vector3.right; break; case Direction.down: rcDir = Vector3.down; break; case Direction.left: rcDir = Vector3.left; break; case Direction.up: rcDir = Vector3.up; break; } rh = Physics2D.Raycast(transform.position, rcDir, 1, wallLayerMask); if (rh.collider != null && canOpenChest) { Door d = rh.collider.gameObject.GetComponent <Door>(); //Debug.Log("checking door " + d.isLocked + " " + d.isClosed + " " + PlayerInventory.HasKeys() + " " + PlayerInventory.keys); if (d != null && d.isLocked && d.isClosed && PlayerInventory.HasKeys()) { PlayerInventory.AddKey(-1); d.UnlockDoor(); return(true); } LootActivatorTile l = rh.collider.gameObject.GetComponent <LootActivatorTile>(); if (l != null) { canOpenChest = false; l.OpenLoot(); return(true); } ShopActivatorTile s = rh.collider.gameObject.GetComponent <ShopActivatorTile>(); if (s != null) { canOpenChest = false; s.OpenShop(); return(true); } } return(false); }
public void OnTriggerEnter2D(Collider2D other) { ParticleManager.Instance.PickUp(transform); inv.AddKey(this); base.OnTriggerEnter2D(other); }
private void OnTriggerEnter2D(Collider2D collision) { if (collision.tag == "Player") { if (isKey) { PlayerInventory.AddKey(1); } else { PlayerInventory.AddGold(goldAmount); } Destroy(gameObject); } }
void OnTriggerEnter(Collider c) { if (c.CompareTag("Player") == false) { return; } PlayerInventory inventory = c.GetComponent <PlayerInventory>(); if (inventory == null) { return; } inventory.AddKey(); Destroy(this.gameObject); }
private void OnTriggerEnter(Collider other) { if (other.CompareTag("Player")) { PlayerInventory inventory = other.GetComponent <PlayerInventory>(); if (inventory == null) { return; } // Check if inventory has space if (inventory.IsEmpty()) { // Add to inventory inventory.AddKey(this); // Destroy key Destroy(gameObject); } } }
public void AddKeys(int amount) { ButtonClicked(); PlayerInventory.AddKey(amount); }