Wait inside a non void method

Hello. I’ve been searching about this for hours and have found multiple answers to similar questions but not similar enough for me to find a solution. Anyway my problem is:
I have a method GetResultMyTeam that takes an object of class Match and returns an int[2] result for it, based on user input. The problem for me is how can I wait for the user input inside this method?
The method I’m running is as follows:

int[] GetMyTeamResult(Match PlayedMatch)
    {

        int[] test = new int[2];
        UIManager.GetComponent<UIManager>().HideOffers();
        UIManager.GetComponent<UIManager>().HideMatchweek();
        UIManager.GetComponent<UIManager>().ShowMatchday();
        // it should wait here
        test[0] = md_manager.GetComponent<MatchdayManager>().HomeTeamGoals;
        test[1] = md_manager.GetComponent<MatchdayManager>().AwayTeamGoals;
        return test;

Firstly I show the proper UI so that the user can input the result and then get the HomeTeamGoals and AwayTeamGoals variables and set them to the test array, which is returned. The problem obviously is that the test array gets filled before the user has a chance to input any data. So I want the method to wait until the user does input some data.
I tried

  1. To create a couroutine only to wait. But time waits only inside the couroutine, the method returns the wrong value anyway.

  2. To replace the whole method by a couroutine but it didn’t seem too good of an idea have some other results being given by methods and others by coroutines. Besides I couldn’t figure out how to set input paramaters to the couroutine and have it return values the same way the method would. If this is the way to go do tell me how I can implement it correctly.

I think you need to think about the problem differently.

I don’t think don’t really want to wait per se - that is you don’t want to stop Unity from processing everything. What you want to do is not process your test array until all the input has been filled - does that sound right?

If so, I think you can easily do this using a number of schemes. Off the top of my head, you don’t want the function you show as is - you need to do some restructuring.

The algorithm goes something like this:

  1. show your UI input “screen” (the buttons where you collect the input).

  2. for each input item, when the input is entered and validated, call (in #3 below ) a function that takes as a parameter which array item the input belongs to and its value. Essentially, your send the function a message on input - so essentially set up #3 as event handler. Each input item has an event listener that sends the data to #3

  3. this is the function that handles the input messages. Inside it you will decide if all the necessary inputs have been received, and if so then you process the test array (or call a function that does). and close your input screen

I think that approach will take care of your problem. Of course, if you need to suspend parts of the game while you are waiting for this input, you can easily set a boolean to handle that when you show the UI input screen, and check that in the relevant parts of your game, and then set it back when you get all the input.