Guest User

Untitled

a guest
Jan 23rd, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 KB | None | 0 0
  1. when i plant multiple bombs at a time, the explosion occurs on the position of the last bomb. a for loop would be a solution but i don't know apply the arrays on this code:
  2.  
  3.  
  4.  
  5. function PlantBomb()
  6. {
  7. bombPos = transform.position + (transform.forward * 2);
  8. var theBomb = Instantiate(BombPrefab,bombPos,Quaternion.identity);
  9. newBombPos = bombPos;
  10.  
  11. yield WaitForSeconds(2);
  12.  
  13. Explode();
  14. Destroy(theBomb.gameObject);
  15. }
  16.  
  17. function Explode()
  18. {
  19.  
  20. Instantiate(ExplosionPrefab,bombPos,Quaternion.identity);
  21. yield WaitForSeconds(0.1);
  22.  
  23. //BombPlanted -= 1;
  24. SpreadExplosion();
  25.  
  26.  
  27. }
  28.  
  29.  
  30. function SpreadExplosion()
  31. {
  32.  
  33. expLocX = bombPos.x;
  34. expLocY = bombPos.y;
  35. expLocZ = bombPos.z;
  36. ExplosionLength = MaxExplosionLength * 2;
  37.  
  38. SpreadPosX();
  39. SpreadPosZ();
  40. SpreadNegX();
  41. SpreadNegZ();
  42. }
  43.  
  44. function SpreadPosX()
  45. {
  46. for (xx = expLocX + 2; xx < expLocX + ExplosionLength + 1; xx += 2)
  47. {
  48. var explosionXX = Vector3(xx,expLocY,expLocZ);
  49. Instantiate(ExplosionPrefab,explosionXX,Quaternion.identity);
  50. yield WaitForSeconds(0.1);
  51. }
  52. }
  53.  
  54. function SpreadPosZ()
  55. {
  56.  
  57. for (zx = expLocZ + 2; zx < expLocZ + ExplosionLength + 1; zx += 2)
  58. {
  59. var explosionZX = Vector3(expLocX,expLocY,zx);
  60. Instantiate(ExplosionPrefab,explosionZX,Quaternion.identity);
  61. yield WaitForSeconds(0.1);
  62. }
  63. }
  64.  
  65. function SpreadNegX()
  66. {
  67. for (xz = expLocX -2; xz > expLocX - ExplosionLength - 1; xz -= 2)
  68. {
  69. var explosionXZ = Vector3(xz,expLocY,expLocZ);
  70. Instantiate(ExplosionPrefab,explosionXZ,Quaternion.identity);
  71. yield WaitForSeconds(0.1);
  72. }
  73. }
  74.  
  75. function SpreadNegZ()
  76. {
  77.  
  78. for (zz = expLocZ - 2; zz > expLocZ - ExplosionLength - 1; zz -= 2)
  79. {
  80. var explosionZZ = Vector3(expLocX,expLocY,zz);
  81. Instantiate(ExplosionPrefab,explosionZZ,Quaternion.identity);
  82. yield WaitForSeconds(0.1);
  83. }
  84. }
Add Comment
Please, Sign In to add comment