Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

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.