Hi! So I’ve been trying to figure this out for 2 days now; it’s time to ask for help.
My goal: Create simple memory card game (the kind where you try to flip over two of the same cards etc…)
What I’m stuck on: Trying to get the cards to spawn randomly every game.
Here’s what I thought I’d do:
using UnityEngine;
using System.Collections;
public class RandomCardLocations : MonoBehaviour
{
public GameObject card1;
Vector3[] cardLocations = {Vector3 (-1.8, 0, 0), etc...};
void Start()
{
for (int i = 0; 1 < 10; i++)
{
float number = Random.Range(0F, cardLocations.length);
Debug.Log (number);
Instantiate(card1, cardLocations[number]);
remove.cardLocations[number];
}
}
}
The basic idea is that there is an array with 20 some-odd Vector3 positions. A random number generator picks one of these positions randomly, spawns the object there, then removes that location from the array so it can’t be picked again.
The random number generator is bound by the length of the array, so you will always be pulling from the right space (won’t get “array.position[456]” when there are only 3 positions left).
List of my problems:
-
Code Retarded (ID10T Error code [idiot] xD)
-
Vector 3 array won’t work. Like, at all. What am I doing wrong? I’m working on a Surface Pro, but that shouldn’t have any effect, should it? More specifically, when I create any kind of array, no matter where, Mono says that ‘void start’ should be removed. WHAT?!
-
How to remove something from an array?
-
Once I get the for-loop and array up and running, the way the code is now it will spawn the same object at all locations (in a random order. GREAT). Any suggestions?
-
Can’t pay for college. Can you help? Oh, wait, wrong forum…
So yeah. Any help at all, monetary or otherwise, is welcome and greatly needed. Anyone’s two cents are appreciated.