Skip to content

Instantly share code, notes, and snippets.

@SiarheiPilat
Created February 5, 2022 15:07
Show Gist options
  • Save SiarheiPilat/b0740b13ae14ac895792d6cb6422e7ea to your computer and use it in GitHub Desktop.
Save SiarheiPilat/b0740b13ae14ac895792d6cb6422e7ea to your computer and use it in GitHub Desktop.
Array randomise example.
using UnityEngine;
using System.Collections;
// taken from https://answers.unity.com/questions/1189736/im-trying-to-shuffle-an-arrays-order.html
public class DeckShuffle : MonoBehaviour {
public GameObject[] decklist;
private GameObject tempGO;
void Start () {
Shuffle();
}
public void Shuffle() {
for (int i = 0; i < decklist.Length; i++) {
int rnd = Random.Range(0, decklist.Length);
tempGO = decklist[rnd];
decklist[rnd] = decklist[i];
decklist[i] = tempGO;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment