Reputation: 10895
Let's assume I have a GameObject 'Player' and two scenes A and B. If I add this GameObject 'Player' on both scenes and then make some changes (e.g. adding a script in Scene A), can I somehow achieve that the GameObject 'Player' stays the same in both A and B? Or do I have to update the GameObject in both scenes manually?
I couldn't find a convenient way to achieve this.
Upvotes: 5
Views: 3397
Reputation: 963
If you just need to persist GameObjects between scene transitions you can use DontDestroyOnLoad() method.
Something like this should makes de deal:
using UnityEngine;
using System.Collections;
public class MyPlayer : MonoBehaviour {
void Awake() {
DontDestroyOnLoad(this.gameObject);
}
// myPlayer behaviour....
}
Upvotes: 5