I am making a 2d game and am trying to drop a ghost prefab when the player dies that he has to collect to gain his powers back. Any help on how to implement this would be greatly appreciated!
When the player dies I am reloading the scene if that helps at all.
tormentoarmagedoom is right, this isn’t really a technical question, but a stylistic one. There are lots of ways you could do this, it all just depends on the breadth of what you want to accomplish. Personally I wouldn’t even go through the trouble of instantiating a new prefab for the player, I’d just have “living” and “ghost” settings on the main player object that activate/deactivate depending on the state.
Why does the scene reload on player death? Is it the same scene or a new scene? Either way, when the scene starts up, you could just have a different player object active depending on if the player has died or not, so you wouldn’t even have to “drop a ghost prefab”. But here’s how prefab spawning works if you’re unaware of it, or rather, one way you can go about it.
// Make a reference to the prefab, then instantiate a clone of the prefab.
GameObject tempChar = Resources.Load<GameObject>("*Name of your desired spawn prefab here!");
// note that you have to create the Resources folder in your assets and put the prefab there.
// It has to be a folder called Resources, but you can make nested folders called whatever you want.
// in a nested folder the part in quotations would be like "folderName/*nameofprefab*"
// You can also just set tempChar as a public variable in the script and assign it in the inspector,
// if you would rather avoid Resource loading altogether.
GameObject tempCharInstance = Instantiate(tempChar, transform.position, transform.rotation);
// set the position/rotation to wherever you like, probably your spawnpoint or previous character position.