So I'm working on a simple platformer in unity 2d. I created a level generator that generates random terrain, enemies, and player character right at the start of the level. I want to have the camera follow the player character. I tried using the SetParent() method to set the player character as a child of the Main Camera. I got this error message: "Setting the parent of a transform which resides in a Prefab Asset is disabled to prevent data corruption." Is there a way to get around this? Or is there another way I could get my main camera to follow a spawned player character?
Here's the player character spawn potion of my level generator:
if (x == 1)
{
Instantiate(player, new Vector3Int(x, y + 2, 0), Quaternion.identity);
player.transform.SetParent(MainCamera);
}
Any assistance would be most appreciated. Thanks!!