Search Unity

How to write +- in c#;

Discussion in 'Getting Started' started by Pollawat, Jun 18, 2022.

  1. Pollawat

    Pollawat

    Joined:
    Aug 27, 2016
    Posts:
    192
    Hello, I'm a newbie.

    Code (CSharp):
    1.     int A = 5;
    2.     int B;
    3.     void FuctionA()
    4.     {
    5.         if (B = A +- 2)
    6.         {
    7.             Debug.Log("Something Happen");
    8.         }
    9.     }
    As you can see here the code is bugging because I don't know how to write it correctly. I'm trying to tell Unity that if B = A plus 2 (6,7) or minus 2 (4,3) then something happens.

    Thank you.
     
  2. iMobCoding

    iMobCoding

    Joined:
    Feb 13, 2017
    Posts:
    165
    First, you have to use double '=' for comparison. Then code would be:
    Code (CSharp):
    1. if (B == A + 2 || B == A - 2)
     
  3. Neto_Kokku

    Neto_Kokku

    Joined:
    Feb 15, 2018
    Posts:
    1,751