// in Start():    StartCoroutine(FindScoreKeeper());
    IEnumerator FindScoreKeeper()
    {
        float counter = 0;

        while (counter < 5)
        {
            if (GameObject.Find("ScoreKeeper").GetComponent <progTestScoreKeeper>() != null)
            {
                scoreKeeper = GameObject.Find("ScoreKeeper").GetComponent <progTestScoreKeeper>();

                Debug.Log("ScoreKeeper = " + scoreKeeper);

                scoreKeeper.UpdateScore(1);                 // testing that we have access to scoreKeeper.
                scoreKeeper.UpdateScore(-5);
                // break out of the loop and consequently, the FindScoreKeeper() method.
                break;
            }

            // otherwise, wait for 0.1 seconds and try again.
            counter += 0.1f;
            Debug.Log("I couldn't find scorekeeper, trying again. . .");
            yield return(new WaitForSeconds(0.1f));
        }// end of while loop
    }
Пример #2
0
 // Start is called before the first frame update
 void Start()
 {
     scoreKeeper = GameObject.Find("ScoreKeeper").GetComponent <progTestScoreKeeper>();
     scoreKeeper.UpdateScore(1);
 }