I'm trying to generate 6 random ints, then assign them to 6 different objects, however I've found that simply generating the int within the object results in every number being the same, due to them all loading at identical times. To work around this issue I'm trying to generate the 6 in a row, so that the clock timing is different and gives a different number. I'm trying to figure out how to access these 6 variables.
I've tried a variety of different formats using 'GetComponent<>()' and 'GameObject.Find("")' together and storing the resulting script in a monobehaviour varibale (which I think is what might be messing me up), then trying to access the numbers through the variable I'm storing the script in. But when I do this, unity says there is no number variable (or Num1, Num2, etc. in my case) in the script.
Here is what I have, I'll only show the code trying to acquire the variables as I have verified that the variable generation works.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
public class NumberButton : MonoBehaviour
{
public int Num;
public GameObject Game;
void Start()
{
MonoBehaviour Game = GameObject.Find("Game").GetComponent<GameInit>();
print(Game.name);
if (gameObject.name == "Button1")
{
Num = Game.Num1;
}
else if (gameObject.name == "Button2")
{
Num = Game.Num2;
}
//There are 4 more of these, 1 for each button, I realize this is terrible code etiquette.
GetComponent<TextMesh>().text = Num.ToString();
}
}
If it works, each button should be assigned their variable based on their name, so Button1 gets Num1 from the GameInit script stored in the GamObject "Game". In actuality nothing is grabbed from GameInit, all the Num variables in the grabber objects are equal to 0, despite the variables in GameInit not being 0.