Hi.
I wrote below code for set Instantiated prefab to parent of the player. but it don’t work and give me below error.
error: " Setting the parent of a transform which resides in a prefab is disabled to prevent data corruption."
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class FallingShieldItem : MonoBehaviour
{
public GameObject PlayerSheild;
public GameObject player;
void OnTriggerEnter2D(Collider2D other)
{
if (other.gameObject.tag == "Player")
{
GameObject SheildObj = Instantiate(PlayerSheild, player.transform.position, Quaternion.identity);
SheildObj.transform.parent = player.transform;
Destroy(gameObject);
}
}
}
while I used this code for set Instantiated prefab to player parent.
SheildObj.transform.parent = player.transform;
can anyone tell me why unity give me this error?
Thanks.