Hey!
So, I’m not sure this is possible, but I’m hoping - if it is, someone here might have a solution, I’ve done some googling, but either the information isn’t out there (probably meaning it’s impossible) or I’m just googling with the wrong words…
What I’m trying to do, is have a “GameObject Variable” named, the same thing that the In-Game Object is named, but… I don’t exactly want to type out (not that it would be an issue, I just figure it would make my code “nicer” to not do so) “GameObject H1 = GameObject.Find(“H1”);” with varied names over and over.
So far, I have got this far in the code “GameObject H1 = GameObject.Find(Alpha + Numeral.ToString());” - which works - but doesn’t quite do the next part I’m hoping for, which would be " new GameObject Alpha + Numeral.ToString() = GameObject.Find(Alpha + Numeral.ToString()); is there anyway to do this?
I will paste my raw code beneath - just so you can see (easier) what I’m going for…
using UnityEngine;
using System.Collections;
public class PieceCreator : MonoBehaviour {
private int x = 1;
private string alpha;
private int numeral;
void Awake()
{
}
void Start()
{
for(int i = 1; i >= 16; i++)
{
AlphaName();
NumeralName();
GameObject tempBlack = GameObject.Find(alpha + (numeral.ToString()));
GameObject + numeral.ToString() = tempBlack;
x++;
}
}
void AlphaName()
{
if (x == 1)
{
alpha = "H";
}
if (x == 2)
{
alpha = "H";
}
if (x == 3)
{
alpha = "H";
}
if (x == 4)
{
alpha = "H";
}
if (x == 5)
{
alpha = "H";
}
if (x == 6)
{
alpha = "H";
}
if (x == 7)
{
alpha = "H";
}
if (x == 8)
{
alpha = "H";
}
if (x == 9)
{
alpha = "G";
}
if (x == 10)
{
alpha = "G";
}
if (x == 11)
{
alpha = "G";
}
if (x == 12)
{
alpha = "G";
}
if (x == 13)
{
alpha = "G";
}
if (x == 14)
{
alpha = "G";
}
if (x == 15)
{
alpha = "G";
}
if (x == 16)
{
alpha = "G";
}
}
void NumeralName()
{
numeral = x;
Debug.Log("numeral = " + numeral.ToString());
}
}
Thank you in advance - if anything I have said is unclear, I can try to re-explain, but unfortunately I don’t know all the “proper jargon”, sorry if I’m really confusing!