Referencing uninstantiated GameObject within a class?
Hi! I've started making my first small game and I'd like help with something I can't seem to figure out. It's a Pairs-type game; I have 6 different card prefabs that are assigned to the script and I wanted to create a class containing methods to ease the coding process of whatever I do within the Start() method. The thing is I can't seem to reference these game objects within a class. In the following code there is an attempt at creating a method that will one instance of every card GameObject to a list.
This error is shown for each Add method argument: "An object reference is required for the non-static field, method, or property 'Spawner.[insert GameObject name]'"
If instead of trying to do this within a class I do this List Adding within the Start() method, it works just fine, but I don't won't to write all that every time I need to populate the list and whatever else I might want to do with the list. How could I solve this?
public class Spawner : MonoBehaviour {
//Declaring GameObjects
public GameObject squareCard;
public GameObject circleCard;
public GameObject triangleCard;
public GameObject pentagonCard;
public GameObject diamondCard;
public GameObject heartCard;
class AvaiableTypes
{
List<GameObject> avaiableTypes = new List<GameObject>();
public void AddAll()
{
avaiableTypes.Add(squareCard);
avaiableTypes.Add(circleCard);
avaiableTypes.Add(triangleCard);
avaiableTypes.Add(pentagonCard);
avaiableTypes.Add(diamondCard);
avaiableTypes.Add(heartCard);
}
}
[...]
Your answer
Follow this Question
Related Questions
How can I change a function from another script? 1 Answer
How to make a class that can be accessed from any script in a project. 2 Answers
Class extension (player.STR to player.Stats.STR) 1 Answer
Game Manager can't decide what the instance of the object is despite just making an instance of it 1 Answer