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
}
}
}
}