void CheckChest(RaycastHit2D rayLeft, RaycastHit2D rayRight) { bool hitChest = false; GameObject chestObject = null; ChestController cc = null; if (rayLeft.distance <= 0.3f && rayLeft.collider.tag.Contains("Chest")) { hitChest = true; chestObject = rayLeft.collider.gameObject; cc = chestObject.GetComponent <ChestController>(); } else if (rayRight.distance <= 0.3f && rayRight.collider.tag.Contains("Chest")) { hitChest = true; chestObject = rayRight.collider.gameObject; cc = chestObject.GetComponent <ChestController>(); } else { return; } if (!hitChest) { return; } else if (!cc.isClosed) { return; } else { cc.Open(); } }
private void OnCollisionEnter2D(Collision2D collision) { // so using tilemaps, we can make new tilemaps and assign different tags to them, for ex: water and ground. //Debug.Log("player has collided with " + collision.collider.name + " with tag: " + collision.gameObject.tag); if (collision.gameObject.tag == "groundable") { GroundPlayer(); } if (collision.gameObject.tag == "hangable" && !Player.instance.isGrounded) { Hang(); } if (collision.gameObject.tag == "breakable" && !Player.instance.isGrounded) { Hang(); } if (collision.gameObject.tag.Contains("Enemy")) { EnemyController enemy = collision.gameObject.GetComponent <EnemyController>(); if (collision.gameObject.tag.Contains("Slime")) { } if (!enemy.attributes.isDead) { Player.instance.TakeDamage(enemy.attributes.damage); if (Player.instance.health <= 0) { GameManager.instance.KillPlayer(); } } } if (collision.gameObject.tag.Contains("Chest")) { //print("collided with chest"); ChestController cc = collision.gameObject.GetComponent <ChestController>(); if (cc.isClosed) { cc.Open(); } } }