- Home /
Question by
AceOfSevens7 · Nov 19, 2017 at 11:00 PM ·
instantiatespriteunity 2draycasting
How can I instantiate a different sprite depending on where Raycasting goes?
Hi! Hopefully, I can explain what I'm trying to do. I'm creating a Bomberman copy (SNES) and I'm struggling with creating the sprites for the bomb once it explodes. Here's my code for the raycasting:
private IEnumerator expandExplosions(Vector2 dir){
explosionRange = Movement_white.bombRange;
for (int i = 1; i < explosionRange; i++) {
RaycastHit2D blockHit;
blockHit = Physics2D.Raycast (transform.position, dir, i, mask);
if (!blockHit.collider) {
Vector2 posEx = new Vector2 (transform.position.x, transform.position.y);
Instantiate (explosionPrefab, posEx + (i * dir), explosionPrefab.transform.rotation);
} else if (blockHit.collider.CompareTag("Block")){
Destroy(blockHit.collider.gameObject, 0.5f);
} else {
break;
}
}
yield return new WaitForSeconds (0.5f);
}
This is working as intended; it detects walls and blocks, stops where it has to and destroys what it can. The problem I'm having is that I can't figure out how to instantiate a bomb sprite that is different than the center one. Right now it only uses 1 sprite and my goal is to have, for example if a bomb expands 2 squares: one center sprite, one sprite that's just goes streight in the the direction it has to, and a final sprite that ends in a semicircle. I'd love to hear any suggestions, thanks!!
Comment