Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

C# This if statement is driving me INSANE

Discussion in 'Scripting' started by darthbator, Nov 29, 2012.

  1. darthbator

    darthbator

    Joined:
    Jan 21, 2012
    Posts:
    169
    Code (csharp):
    1. else if (tmpRemoteObj != null  (hit.collider.gameObject.layer != (int)Indexes.Layers.enemyActor || hit.collider.gameObject.layer != (int)Indexes.Layers.playerActor)) {
    2.     unsetRemoteTarget();
    3. }
    4.  
    All I am trying to do is check to see if a remote object is defined. If the remote object is defined and it's not on any of my actor layers I want to unset the current target. This appears to be the part causing the issue

    (hit.collider.gameObject.layer != (int)Indexes.Layers.enemyActor || hit.collider.gameObject.layer != (int)Indexes.Layers.playerActor)

    If I remove the parenthesis and leave only ONE of the evals it works fine for example leaving only (hit.collider.gameObject.layer != (int)Indexes.Layers.enemyActor). Why is that happening? I have used that syntax to before to do things like

    if ((A||B||C||D) (E||F||G))

    without any issue but here it doesn't seem to work and I really cannot seem to figure out why. Any help would be most appreciated.
     
  2. darthbator

    darthbator

    Joined:
    Jan 21, 2012
    Posts:
    169
    Soooo my logic was kinda junky..... That || should have been ....... I am now not insane!