picking up guns

ive been working on a horror fps game in unity for a while now but i dont know how to pick guns up my game starts off when you are being tortured, but you then somehow kill everyone and escape the room you then find a gun which "you pick up" and escape the building.

so can anyone tell me how i would do this?

there is a way to do this. you will have to use a parenting technique. makeing the gun a child of the player. this will take work but here is how to do it. First you will have to make a sphere. gameObject-> create other-> sphere. after you have one put it exacly where you want the center of your gun to be spawned at. then drag it in your hierarchy onto your player. thus making it a child of the player. then uncheck the mesh renderer on the sphere and remove the collider component. make sure the player is tagged "Player". make sure that in the script below that the sphere you created goes in the SpawnTo place and that your gun goes in the Gun place. there should be a place to drag it onto after you have attached this script to your gun it should give you

  • SpawnTo-(Transform)
  • Gun-(Transform)

now make this script.

var SpawnTo:Transform;
var Gun : Transform;
function OnCollisionEnter(hit:Collider)
{
if(hit.gameObject.tag == "Player")
{
Gun.parent = SpawnTo;
Gun.transform.position = SpawnTo.transform.position;
Gun.transform.rotation = SpawnTo.transform.rotation;
}
}

Hope this Helps!