Get the rotation matrix if you have the start and end position

Hello, I’m trying to get the needed rotation to get a small cube from a rubik’s cube to the right position.

I made my rubik’s cube positions like a matrix from -1 to 1 on the x,y and z axis.

Now my problem is, if I have for example the position (1,1,1) and the end position should be (-1,1,1) how can I get something like a rotation matrix that says I have to rotate 90° on the y-axis?

I also tried using the mathematics package but I can’t find any soltuion.

A rotation of 90° on the y-axis is most easily done using Euler angles. You can get a rotation in the form of a quaternion, and from there to a matrix, using code like this:

Quaternion rotation = Quaternion.Euler(0, 90, 0);
Matrix4x4 m = Matrix4x4.Rotate(rotation);

More info: Quaternions and rotation matrices.