title: How can I fix this bug in my chess game where a move shows up on top of a piece?
body: <p>I was making a chess game, and all is well except that for example, a pawn, shows a move marker on a piece in front of it (pawns cant move like that). The game won't let you move there, since the move marker code is separate from the actual move code and check.</p>
  
  <p>I have already tried many different approaches, such as iterating through every piece and checking if each piece is in front of the selected piece, as well as making sure that each piece iterated through is not the selected piece.</p>
  
  <pre><code>if (pieceSelected &amp;&amp; !finishedPlacingMoveMarkers)
  {
      if (selectedPiece.GetComponent&lt;BlackPawn&gt;())
      {
          if (selectedPiece.transform.position.y + 1 &lt;= 3.5)
          {
              foreach (Transform child in pieces.transform)
              {
                  if (child.tag == "Piece")
                  {
                      if (obj.position == new Vector3(selectedPiece.transform.position.x, selectedPiece.transform.position.y + 1) &amp;&amp; child.position != selectedPiece.transform.position)
                      {
                          if (child.position == new Vector3(selectedPiece.transform.position.x, selectedPiece.transform.position.y + 1))
                          {
                              noMoveHighlight = true;
                              break;
                          }
                          else
                          {
                              noMoveHighlight = false;
                          }  
                      }    
                  }
              }
  
              if (!noMoveHighlight)
              {
                  GameObject move1 = Instantiate(tileMoveHighlight);
                  move1.transform.parent = moveTileHighlights.transform;
                  move1.transform.position = new Vector3(selectedPiece.transform.position.x, selectedPiece.transform.position.y + 1, -0.9f);
              }      
          }
  
          finishedPlacingMoveMarkers = true;
      }
  }
  </code></pre>
  
  <p>I expect the results to look like this when i select the pawn:
  <a href="https://i.stack.imgur.com/LRXFT.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/LRXFT.png" alt="https://i.imgur.com/iSA3mFi.png"></a></p>
  
  <p>But they look like this:
  <a href="https://i.stack.imgur.com/gNENF.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/gNENF.png" alt="https://i.imgur.com/s25kb5E.png"></a></p>
  
  <p>Please help!</p>