我正在制作一个游戏项目,很有趣,我遇到一个为我的对话系统工作的单身人士的问题,当我用对话框系统加载场景时工作正常,但是如果我改变场景然后返回[Singleton]实例“ ConversationManager”已被破坏。返回null。
##
# configuration file for syslogd and aslmanager
##
? [= Sender firefox] ignore
# redirect com.apple.message.domain to /var/log/DiagnosticMessages
? [T com.apple.message.domain] store_dir /var/log/DiagnosticMessages exclude_asldb
# authpriv messages are root/admin readable
? [= Facility authpriv] access 0 80
# remoteauth critical, alert, and emergency messages are root/admin readable
? [= Facility remoteauth] [<= Level critical] access 0 80
# broadcast emergency messages
? [= Level emergency] broadcast
# save kernel [PID 0] and launchd [PID 1] messages
? [<= PID 1] store
# save everything from emergency to notice
? [<= Level notice] store
# save lpr info level and above
? [<= Level info] [= Facility lpr] store
# save all mail, ftp, local0, and local1 messages
? [= Facility mail] store
? [= Facility ftp] store
? [= Facility local0] store
? [= Facility local1] store
答案 0 :(得分:0)
您需要确保不要破坏重物。您的逻辑有缺陷。向后看,下面不会在场景负载下破坏。如果要替换游戏对象,请确保它具有相同的值。
void Awake()
{
//Check if instance already exists
if (instance == null)
//if not, set instance to this
instance = this;
//If instance already exists and it's not this:
else if (instance != this)
//Then destroy this. This enforces our singleton pattern, meaning there can only ever be one instance of a GameManager.
Destroy(gameObject);
//Sets this to not be destroyed when reloading scene
DontDestroyOnLoad(gameObject);
}
答案 1 :(得分:0)
几乎没有什么老问题,但是最近在使用完全相同的Singleton脚本时遇到了同样的问题。
您不能在广告素材上使用
[ExecuteInEditMode]
属性 实现该Singleton模式的类。
因此,请在您的类上删除该属性,然后将“编辑器”逻辑移至另一个非单一类。