how to setan animator&rigidbody after instantiation in my code
i am making a pickup script, and want to set 3 components in the pistol prefab from my pickup script after i instantiate: camAnimator(animator), crosshairAnimator(Animator), and Player(Rigidbody) how would I do this from my code? I've tried my best but now I feel stuck.
public GameObject playerGun;
public LayerMask weaponLayer;
public Camera camera;
public GameObject weaponHolder;
public Transform gunTrans;
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.E))
{
RaycastHit hit;
if (Physics.Raycast(camera.transform.position, camera.transform.forward, out hit, maxDistance, weaponLayer))
{
if (hit.rigidbody != null)
{
pickUp();
}
}
}
}
void pickUp()
{
Instantiate(playerGun, gunTrans.position, gunTrans.rotation);
playerGun.transform.parent = weaponHolder.transform;
}
}
Comment
Your answer
Follow this Question
Related Questions
Rigidbody / Animator Moving Y Position - bug? 1 Answer
3D Trigger collider slows player moved by forces 0 Answers
How to get objects to shake and fall off in 3D,Getting an object to shake and fall off in 3D 0 Answers
Player passing through walls when in corners 0 Answers
object moves up when two opposing horizontal forces add up 0 Answers