So I have a jetpack upgrade in which if you clikc a button a jetpack will spawn and you can fly with it. I already have a script inplace to spawn in the jetpack and to change the players behaviour i just run into issues when i try to spawn in the sprite of the jetpack. So here is my code:
function jetpackon ()
{
if(Boom.gold >= 50)
{
var jetpacksprite : GameObject;
jetpackbought = true;
var jetpackposition = target.position;
var TempSpawnjetpack = Instantiate (jetpacksprite,jetpackposition, Quaternion.identity);
jetpacksprite.transform.parent = transform;
Boom.gold = Boom.gold -50;
}
}
In the scene I have a prefab with the jetpack sprite in it and i placed it in the slot of my player as jetpacksprite. Now the jetpack spawns in but it doesnt follow the player and i get this error code:
“Setting the parent of a transform which resides in a prefab is disabled to prevent data corruption.
UnityEngine.Transform:set_parent(Transform)”
Not sure how else i should do this so i thought i would ask it here. If you guys could just tell me what i am doing wrong that would be great. Thank you for reading this :3