- Home /
Attach Transform to another GameObject
The scenario I am trying to accomplish is attaching a turret to a mount point on a ship. I have gotten as far as bringing in the prefab and assigning it as a child object with the following code:
GameObject leftFixedGun = (GameObject)MonoBehaviour.Instantiate(Resources.Load("Laser Fixed Gun"), leftMountPoint.position, leftMountPoint.rotation);
leftFixedGun.transform.parent = player.transform;
The problem is, it takes on the rotation of the mount point object, obviously, which isn't exactly what I'm going for.
I have a couple ideas of how to fix this problem, but would really like it to be a different solution all together.
My idea to fix this problem would be to rotate the transform at leftGunMountPoint
in order to align the attached gun correctly.
The ideal solution, and the one I would like help with, would to be to align a local mountPoint
transform I have under the leftFixedGun
to a leftGunMountPoint
under the ship I am trying to attach the gun to.
I hope this makes sense, and if it doesn't please feel free to leave questions in the comments. Also, please let me know if I am going about this completely wrong =)
Thanks!
Your answer
Follow this Question
Related Questions
Position of a GameObject 2 Answers
C# GameObjectList not Setting Parent 0 Answers
How can I manipulate the script attached to a Transform Object? 4 Answers
How to call and run a function from another script on a transform. 0 Answers
Raycast to Disable Script 0 Answers