Adding a gun to n arm

I have a mesh of a gun and i want to be able to add this to the arm of a character in code, what is the best way in unity to combine the transforms?

can you not do
gun.transform.parent = character.transform;

hi, what is the problem if you code the line you wrote above? parenting is the key to attach anything…