Created
February 5, 2022 15:07
-
-
Save SiarheiPilat/b0740b13ae14ac895792d6cb6422e7ea to your computer and use it in GitHub Desktop.
Array randomise example.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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