public bool MoveRobot(int x_dir, int y_dir) { bool drive_sound = false; int x = x_pos + x_dir, y = y_pos + y_dir; if (!moving && !falling && !turning) { if (grid_script.CheckTile(x, y)) { // If tile is within the grid if (grid_script.GetTile(x, y).transform.childCount == 0) { // If tile is empty, move to tile Movement(x, y); if (!drive_sound) { AudioManager.instance.Play("drive"); drive_sound = true; } return(true); } else { if (grid_script.GetTile(x, y).transform.GetChild(0).gameObject.tag == "Robot") { // If tile is not empty, check if tile's child is robot RobotMovement robot_scr = grid_script.GetTile(x, y).transform.GetChild(0).gameObject.GetComponent <RobotMovement>(); if (robot_scr.MoveRobot(x_dir, y_dir)) { // If robot is pushed, move this robot to pushed robot's old position Movement(x, y); return(true); } return(false); } return(false); } } else { // If tile is not within grid fall off edge of the map Fall(x, y); return(true); } } AudioManager.instance.Stop("drive"); return(false); }