Creating a stack

So currently i’m trying to make a deck of cards that gets randomly shuffled and placed into a stack.

However creating the stack, it wont accept GameObject as a type.

 public static Stack<GameObject> Deck = new Stack<GameObject>();

can anybody find what i’m doing wrong?

Given you didn’t post the error that you’re receiving, i can only guess.

Stack exists in the namespace System.Collections.Generic, if this isn’t added, which it isn’t by default based off the templates that Unity uses to create c# scripts, you will need to add it.

You will also need to ensure you’re using the namespace UnityEngine, this is where the type GameObject exists.

example:

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

public class SomeNewScript : MonoBehaviour 
{
	public static Stack<GameObject> ob = new Stack<GameObject>();

	public void Start()
	{
	}
	
	public void Update()
	{
	}
}

The ob static field now exists on the class and is not an instance member any longer.

// in some method

ob.Push(SomeGameObjectInstance)

// pop off stack

GameObject nextObect = ob.Pop();