How to keep my character STUCK to the floor?!

I have been working non-stop on trying to find a solution to this for about four days without success. This might sound like an obvious question, but the floor is a rotating cube and I am new to Unity. When the character reaches the side he does turn and go down using this code:

//Rotate down after plane ends (BUGGED!)
    var down = transform.TransformDirection (Vector3.down);
    if (!Physics.Raycast (transform.position, down, 1)) {
        print ("There is nothing in front of you");
        transform.Rotate(Vector3.right);

It says it is bugged because what happens is, if he isn’t going off in the right direction, he will be stuck in a continuous loop, forever. I was just wondering how to make him ALWAYS stick to the floor, no matter what. More often than no he flies into space, even if the cube rotates too fast, which it sometimes does.

At the moment he is rotating around the Y axis using euler angles:

 if(Input.GetKeyDown("d")){
 		transform.eulerAngles.y = 90;
 	}
    if(Input.GetKeyDown("w")){
        transform.eulerAngles.y = 360;
    }

This is fine until the cube isn’t perfectly facing the camera, and the character is not perfectly on that Y axis, otherwise, once more, he goes flying off into space. And he really, really needs to remain on the cube! Thank you all.

public GameObject cube;		//Cube reference.
public float cubeYLoc;
public float cubeYScale;
public void Awake()
{
	//Get the scale so we can get the top of the cube instead of the middle.
	cubeYScale = cube.transform.lossyScale.y;
}

//Boolean to see if the player is on the cube or not.. 
public bool playerIsOnCube = false;
public GameObject player;	//Player reference.
public void Update()
{
	if(playerIsOnCube)
	{
		//Want the top not the middle.
		cubeYLoc = cube.transform.position.y + cubeYScale;
		//Stick the players Y Location to the cube.
		player.transform.position = new Vector3(player.transform.position.x, cubeYLoc, player.transform.position.z)
	}
}

Tried that it comes up with errors. Lines 1,3,5,7; “Unexpected game object, float, float, void…” And on line 13; “expecting : found =”.