Two Objects collide then move

I’m trying to make it that if the player is touching a certain square and they hit the “w” key, then they’ll move up. I know how to get them to move, the only problem I’m having is making it so that they will only move if on these certain squares.

So basically, something along the lines of:

if(Player collides with square && Input.GetKeyDown("w"))
     Player.transform.Translate(0,0,1);

I just need to figure out what to put in place of Player collides with square.

I would use a trigger: place a trigger volume close to the square, and use OnTriggerEnter to set a boolean flag that shows it’s touching the trigger (player script):

var inTrigger = false;

function OnTriggerEnter(other: Collider){
  if (other.name=="SquareTrigger"){
    inTrigger = true;
  }
}

function OnTriggerExit(other: Collider){
  if (other.name=="SquareTrigger"){
    inTrigger = false;
  }
}

function Update(){
  if (inTrigger && Input.GetKeyDown("w")){
    Player.transform.Translate(0,0,1);
  }
}

In order to create a trigger volume, create an empty object, add a suitable collider to it (Box Collider, Sphere Collider etc.), adjust its dimensions/position/rotation and check Is Trigger - remember to name it “SquareTrigger” to match the script above (or any name you use in your script)