void OnTriggerEnter2D(Collider2D collider) { if (collider.tag == "Player") { Debug.Log("WORK"); Players.PC_Class player = collider.GetComponent <Players.PC_Class>(); switch (Type.ToString()) { case "Health": if (player.HP_Pots.Count < player.InventorySize && player.IsAlive == true) { player.HP_Pots.Add(this); Destroy(Pot); } break; case "Mana": if (player.MP_Pots.Count < player.InventorySize && player.IsAlive == true) { player.MP_Pots.Add(this); Destroy(Pot); } break; } } // If we want enemies to be able to take potions or items as well else if (collider.tag == "Enemy") { Debug.Log("That enemy stole your potion!"); Destroy(Pot); } }
void OnTriggerEnter2D(Collider2D collider) { if (collider.tag == "Player") { PC_Class player = collider.GetComponent <PC_Class>(); player.InventorySize++; Destroy(gameObject); } }
void Start() { _parent = GetComponentInParent <PC_Class>(); for (int i = 0; i < 10; i++) { float spawnXPos = _parent.transform.position.x + distanceToLook; float spawnYPos = _parent.transform.position.y + distanceToLook; GameObject myObstacle = obstacleList[Random.Range(0, obstacleList.Length)]; _spawner.SpawnObstacle(myObstacle, spawnXPos, spawnYPos); } }
void OnCollisionEnter2D(Collision2D collision) { Destroy(gameObject, 1f); if (collision.gameObject.tag == "Player") { Players.PC_Class enemy = collision.gameObject.GetComponent <PC_Class>(); if (enemy != null) { enemy.TakeDamage(_damage); } Destroy(gameObject); } }