360 degree movement according to the camera facing

if(Input.GetKey(“i”)) {
previouskey=“i”;
animation.CrossFade(“moving”);
direction += Vector3.forward;
currentkeydown=true;
}

        if(Input.GetKey("k")){
        	previouskey="k";
            animation.CrossFade("moving"); 
            direction += Vector3.back;
        	currentkeydown=true;
        } 
        			
        if(Input.GetKey("j")){
        	previouskey="j";
        	animation.CrossFade("moving"); 
        	direction += Vector3.left;
        	currentkeydown=true;
        } 
        			
        if(Input.GetKey("l")){
        	previouskey="l";
        	animation.CrossFade("moving"); 
        	direction += Vector3.right;
        	currentkeydown=true;
        } 
    
        //some problem here			
        if(!(direction.x==0&&direction.y==0&&direction.z==0)){
        	transform.localEulerAngles = new Vector3(transform.localEulerAngles.x, Camera.main.transform.localEulerAngles.y, transform.localEulerAngles.z);
        	transform.forward =direction;
        }
        //move the player
        if(currentkeydown){
    	transform.position+=transform.forward*speed;
    }

in the above code, i firstly calculate the vector , direction,which sum up the vector of direction, to set the facing of my character.
it is ok if character can move in 8 direction,
while now i will like to add something which make the character move according to the camera facing.
i have find something like using

transform.localEulerAngles = new Vector3(transform.localEulerAngles.x, Camera.main.transform.localEulerAngles.y, transform.localEulerAngles.z);

but i do not know how to add it to my variable (direction).
can someone give me some advices?

There are some tricky situations with reading euler angles directly, but as long as your camera is relatively parallel to the ground, you can replace line 30 - 33 with:

if (direction != Vector3.zero) {
    direction = Quaternion.Euler(0.0f, Camera.main.transform.localEulerAngles.y, 0.0f) * direction;
    transform.rotation = Quaternion.LookRotation(direction);
}