Hello, I am trying to make a script that would make a GameObject (the weapon) become parented to another GameObject (the player) when the player gets within about 2 meters of the weapon. But I want the player to have to press the button “F” to have it become parented. I would also like to have a text appear that would say something like “press F for weapon”. Additional I have an aiming script that I would want to disable and add a rigidbody to the weapon (which would become unparented) when you pick up a new weapon. I have searched the forums but have not found anything like what I am looking for. Help would be appreciated.
I would think it is better to have all the weapons disabled and already attached to the player.
Then when the player comes in 2 meters it activates.
I want to have the weapons be objects that can be moved instead of things that spawn in places.
And my weapon aiming script already would move the weapon into place. All I want is something to parent the object to the player while enabling the aiming script and disabling the rigidbody.
GameObject (the weapon).parent = GameObject (the player) ?
agree with pezz,it is much simpler that way…
I knew that part, but how would I disable my aiming script and add a rigidbody to the dropped weapon. And how would I get the weapon to become unparented (dropped) while enabling the aim script on the picked up weapon and removing the rigidbody on that weapon?
Try with Transform.parent set to null for the unparented part; GameObject.AddComponent() and Destroy() for attaching/removing components
Ok that works for the parenting/unparenting of the weapons and adding of the rigidbody but how would I disable/enable (not remove) the aiming script. And just to make sure I got this right I would put
weaponname.AddComponent(rigidbody) / weaponname.DestroyComponent(rigidbody)