Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only. On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live. Read our full announcement for more information and let us know if you have any questions.

Problem with OR statement in C #

Discussion in 'Getting Started' started by Sunderer, Mar 20, 2015.

  1. Sunderer

    Sunderer

    Joined:
    Mar 16, 2015
    Posts:
    35
    Hi, I am having problems with the unity rejecting my OR statement:

    Code (CSharp):
    1.     void OnTriggerEnter (Collider other)
    2.     {
    3.         if (other.tag == "Boundary") || (other.tag == "Asteroid")
    4.         {
    5.             return;
    6.         }
    7.        
    8.     Destroy(other.gameObject);
    9.     Destroy(gameObject);
    10.     }
    11. }
     
  2. Effervescent

    Effervescent

    Joined:
    Mar 7, 2015
    Posts:
    31
    I think it's because of missing parentheses:

    Code (CSharp):
    1. if ((other.tag == "Boundary") || (other.tag == "Asteroid"))

    Alternatively, if you don't intend to keep the parentheses inside:

    Code (CSharp):
    1. if (other.tag == "Boundary" || other.tag == "Asteroid")
     
    theANMATOR2b and Sunderer like this.
  3. Sunderer

    Sunderer

    Joined:
    Mar 16, 2015
    Posts:
    35
    Thank you Effervescent, that worked.