Search Unity

Break loop when colliding with object

Discussion in 'Scripting' started by taurib, Dec 21, 2014.

  1. taurib

    taurib

    Joined:
    Nov 20, 2014
    Posts:
    1
    I have a problem with breaking the loop, when it hits "Wall" or "Box" object, but I am not sure, how I should check it. I know the Collision method and to destroy objects with it, but I need to use it in this switch statement.

    Code (CSharp):
    1. void ExpolsionController(Vector3 position)
    2.     {
    3.         float x = position.x;
    4.         float y = position.y;
    5.         float z = position.z;
    6.         for (int i = 0; i < 4; i++)
    7.         {
    8.         outer:
    9.             for (int j = 0; j < bombExpoltionArea; j++)
    10.             {
    11.  
    12.                 switch (i)
    13.                 {
    14.                     case (0):
    15.                         Instantiate(explosion, new Vector3(x + j, y, z), Quaternion.identity);
    16.                         if (Collision.Equals("Wall", "Box"))
    17.                             goto outer;
    18.                         break;
    19.                     case (1):
    20.                         Instantiate(explosion, new Vector3(x - j, y, z), Quaternion.identity);
    21.                         break;
    22.                     case (2):
    23.                         Instantiate(explosion, new Vector3(x, y, z + j), Quaternion.identity);
    24.                         break;
    25.                     case (3):
    26.                         Instantiate(explosion, new Vector3(x, y, z - j), Quaternion.identity);
    27.                         break;
    28.                 }
    29.             }
    30.      
     
  2. jister

    jister

    Joined:
    Oct 9, 2009
    Posts:
    1,749
    make a bool in OnCollisionEnter()?