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!
EDIT:
Thanks to the answer, and if anyone else is wondering about this, easiest way to accomplish this is as follows:
- Create a transform, and line it up with where you want to place the item trying to be mounted.
The following code attached the gun as I wanted.
GameObject laserFixedGun = (GameObject)MonoBehaviour.Instantiate(Resources.Load("Laser Fixed Gun"), leftMountPoint.position, leftMountPoint.rotation); laserFixedGun.transform.parent = player.transform;