Code: Select all
public class PauseButton : MonoBehaviour
{
public bool firstTimePause;
private bool checkIfPause;
public void Awake()
{
firstTimePause = false;
}
public virtual void PauseButtonAction()
{
StartCoroutine(PauseButtonCo());
}
protected virtual IEnumerator PauseButtonCo()
{
yield return null;
checkIfPause = GameObject.Find("SomeObject").GetComponent().Paused;
if (firstTimePause == false && this.gameObject.name == "ResumeBackground" && checkIfPause == true)
{
firstTimePause = true;
Debug.Log("This is getting printed");
}
}
}
Code: Select all
public class StopWatchTimer : MonoBehaviour
{
public Text textTime;
private PauseButton pauseButtonScript;
public GameObject pauseButtonObject;
// Use this for initialization
void Start()
{
pauseButtonScript = pauseButtonObject.GetComponent
();
}
void Update()
{
pauseButtonScript = pauseButtonObject.GetComponent();
Debug.Log(pauseButtonScript.firstTimePause); //this value is always false even if it was already set to true on PauseButton Class
if (pauseButtonScript.firstTimePause == true)
{
//do something
}
}
}
Wenn ich die Klasse so geändert habe, funktioniert sie.
Code: Select all
public class PauseButton : MonoBehaviour
{
public bool firstTimePause;
private bool checkIfPause;
public void Awake()
{
firstTimePause = false;
}
public virtual void PauseButtonAction()
{
StartCoroutine(PauseButtonCo());
}
protected virtual IEnumerator PauseButtonCo()
{
yield return null;
checkIfPause = GameObject.Find("SomeObject").GetComponent().Paused;
firstTimePause = true;
Debug.Log("This is getting printed");
}
}
Dies ist SomeObject mit GameManager
