Aiming in code only.

I'm trying to perform aiming in code only. So i cant use Transform.LookAt.

What a need is a function that takes two Vector3, a object position & and target position. And then returns a aim rotation in euler angles.

Any suggestions on how i can do this?

You can get a rotation (i.e. a Quaternion) from two input Vector3's like this:

var rotation = Quaternion.LookRotation( targetPosition - sourcePosition );

The above will create a rotation which looks along the direction from the source to the target.

From this rotation, you can extract the euler angle values (although it's usually best to work directly with quaternions).

Alternatively, if you want to consider rotation around only one axis, you can compute the angle "manually" in degrees by using the Atan2 like this (this gets the rotation around the y axis, by feeding in the difference between the target & source on the x & z plane:

var delta = targetPosition - sourcePosition;
var targetAngle = Mathf.Atan2(delta.x, delta.z) * Mathf.Rad2Deg;