void OnTriggerEnter(Collider other) { if (other.gameObject.CompareTag("Pick Up")) { if (other.gameObject.GetComponent <Treasure>()) { Treasure coin = other.gameObject.GetComponent <Treasure>(); treasures += coin.value; coin.Explode(); SetTreasureText(); } count = count + 1; SetCountText(); } }
public void ExplodeTreasure(Treasure treasure, int pieces, Vector3 playerPosition) { if ((treasure.transform.localScale.x / (float)pieces) + 0.1f < minDestructionSize) { // if the pieces will be too small, don't explode return; } for (int i = 0; i < 2; i++) { GameObject spawnedTreasure; switch (treasure.color) { case GameManager.ItemColor.BLACK: spawnedTreasure = Instantiate(blackTreasure[GetSpriteIndex(GameManager.ItemColor.BLACK, treasure.GetComponent <SpriteRenderer>().sprite)]); break; case GameManager.ItemColor.BLUE: spawnedTreasure = Instantiate(blueTreasure[GetSpriteIndex(GameManager.ItemColor.BLUE, treasure.GetComponent <SpriteRenderer>().sprite)]); break; case GameManager.ItemColor.RED: spawnedTreasure = Instantiate(redTreasure[GetSpriteIndex(GameManager.ItemColor.RED, treasure.GetComponent <SpriteRenderer>().sprite)]); break; default: spawnedTreasure = null; break; } spawnedTreasure.transform.position = new Vector3(treasure.transform.position.x + (i - 0.25f), treasure.transform.position.y + (i - 0.25f), treasure.transform.position.z); spawnedTreasure.transform.SetParent(treasureParent); float scale = (treasure.transform.localScale.x / (float)pieces) + 0.1f; spawnedTreasure.transform.localScale = new Vector3(scale, scale, scale); currentTreasure.Add(spawnedTreasure.GetComponent <Treasure>()); spawnedTreasure.GetComponent <Rigidbody2D>().AddExplosionForce(500f, playerPosition, 20f); } currentTreasure.Remove(treasure); treasure.Explode(); }