Hi everyone, hopefully someone can help me out here.
I currently have a script attached to an in game weapon, which I want the player to be able to pick up.
When I place the weapon in the world manually the script attached to it works perfectly, however when the weapon has been instantiated it does not work correctly.
The GetComponent code is what is not working on the instantiated object.
Once again it works fine if i place the weapon in the world manually, just not when the object is instantiated. The destroy object code always works. If anyone could shed some light as to why this would be it would help me A LOT. Thanks lads.
How are you assigning the player reference on your pistol script? I’m guessing you’re actually referencing the player prefab on your pistol and not the player in your Scene. Your Instantiate code doesn’t set the reference and it’s not possible for a prefab to reference an object from a scene. I think you need to add this code to your Instantiate code: