Hey I have a specific problem with the DontDestroyOnLoad function for my object.
In my project i have level loader and the player object can change scenes without getting destroyed.
In one level a have an elevator and the player becomes the children object of the elevator while its inside of it
( the working elevator function:
`
private void OnTriggerEnter2D(Collider2D collision)
{
if(collision.tag=="Player")
{
inSwitchArea = true;
Debug.Log("in Area");
collision.transform.parent = transform;
collision.gameObject.layer = 8;
}
}
private void OnTriggerExit2D(Collider2D collision)
{
if (collision.tag == "Player")
{
inSwitchArea = false;
Debug.Log("not in Area");
collision.transform.parent = null;
collision.gameObject.layer = 9;
}
}`
)
After leaving the elevator, its not the children of it anymore, but now the DontDestroyOnLoad(gameObject) isnt working anymore while changing the scene.
I think the parent (elevator) is changing something in the child object (player), but I am not sure what it is and how to fix this. Maybe you have some backround knowledge.
bg, Alex
↧