help with direction

Hello everyone. I have an array which is made up of the four directions : up, down, left or right. I have a grid of gameobjects in my game, I would like that when the mouse clicks any one of the gameobject and then a drag occurs in one of the directions, the object moves up, down, left or right, but only if the direction matches. Eg:

if (right == true){
if swipe direction = right <— correct (show success)
}

if ( right == true) {
and swipe = (up, down, or left) <— wrong (show failed)
}

In essence, I am trying to set a script which states that when the object is touched and dragged, it will only move if the direction matches the random selection of a gameobject in the array. Can anyone help with getting this scripted from the pseudocode I have provided?

Thanks in advance.

try on the 2nd if statement if(!right == true) ! means not or false and stuff