有两个场景,A和B。A中添加了 UI Text 和UIbutton, 点击Button进入B情景。我想Text进去B的时候不消失,官网说用DontDestroyOnLoad这个方法,试了N久都不行,请大神赐教。挂在Text物体上的脚本如下:
public class DontDestroy : MonoBehaviour
{
public static DontDestroy Instance = null;
private void OnDestroy()
{
print(this.gameObject.name + "is Destroy");
}
void Start()
{
if (Instance != null)
{
Destroy(this);
return;
}
Instance = this;
DontDestroyOnLoad(this.gameObject);
}
}
我突然想到,会不会跟UGUI有关?
public class DontDestroy : MonoBehaviour
{
public static DontDestroy Instance = null;
private void OnDestroy()
{
print(this.gameObject.name + "is Destroy");
}
void Start()
{
if (Instance != null)
{
Destroy(this);
return;
}
Instance = this;
DontDestroyOnLoad(this.gameObject);
}
}
我突然想到,会不会跟UGUI有关?