How do I change my code to allow for an inheritable return value?

Hi guys, so I have this basic code that takes a list of items and reorders them in a different list.

I want to use that list in another class. Now I know how to inherit from that class, problem is I’m not sure how to make sure I have a return value.

If I understand correctly using “void” nullifies me having a return value. I’m a bit confused how to reconstruct my code in order to achieve that. Maybe if you show me once I’ll be able to easily do it in the future?

using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class RandomObjects : MonoBehaviour {
    public GameObject[] gos;
    public List<GameObject> randobjects = new List<GameObject>();
    // Use this for initialization
    void Start () {
        gos = GameObject.FindGameObjectsWithTag ("Trivia");

        while (randobjects.Count < gos.Length) {
            int rand = Random.Range (0, gos.Length); //generates a random number from 1-11
            if (randobjects.Contains (gos[rand]) == false) { //checks if a random "trivia" gameobject in the original array exists in the randnumbers list
                randobjects.Add (gos[rand]); //adds the gameobject if not
            }
        }
   
    }
}

Hello again Valda! :slight_smile:
Create a method that returns the appropriate List<> type.
In your case, something like

public List<GameObject> ReorderList(){
         //reorder code goes here
}

If the only class that is going to be using this method is this class, and any child classes, I would suggest changing the method from public, to protected.

Many many thanks, you rock! :slight_smile: