public GameObject MyGameObject;
void Start()
{
// Check on start if gameobject should be enabled or disabled
if (PlayerPrefs.GetInt("MyGoActiveState") == 0)
{
// Should be disabled
MyGameObject.SetActive(false);
}
else
{
// Should be enabled
MyGameObject.SetActive(true);
}
}
// Assuming this is your callback for disabling the object
public void DisableGameObject()
{
// Disable gameobject
MyGameObject.SetActive(false);
// Store in PlayerPrefs that gameobject is disabled
PlayerPrefs.SetInt("MyGoActiveState", 0);
}
// Assuming this is your callback for enabling the object
public void EnableGameObject()
{
// Enable gameobject
MyGameObject.SetActive(true);
// Store in PlayerPrefs that gameobject is enabled
PlayerPrefs.SetInt("MyGoActiveState", 1);
}
1条答案
按热度按时间bxjv4tth1#
使用
PlayerPrefs
:对于单线风扇,也可以像这样设置活动状态,假设0用于表示禁用,其他任何值表示启用: