I want to use a string to reference a gameobject that I already have in my code, but the console says that you can't convert a string to unityengine.object. I have a string that says aaaa and a gameobject that has the name aaaa.
using System.Collections.Generic;
using UnityEngine;
public class WorldRenderer : MonoBehaviour
{
public Transform Tile;
string seed = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaacaaabaaaaaaaa";
public int worldHeight;
public int worldWidth;
private int seedSub = 0;
public GameObject aaaa;
public GameObject aaab;
public GameObject aaac;
void Start()
{
transform.position = new Vector3(worldWidth / 2 * -0.64f + 0.32f, worldHeight / 2 * 0.64f + 0.32f);
for (int height = 0; height < worldHeight; height++)
{
transform.position = new Vector3(worldWidth / 2 * -0.64f - 0.32f, transform.position.y);
transform.position = transform.position - new Vector3(0, 0.64f);
for (int width = 0; width < worldWidth; width++)
{
seedSub = seedSub + 1;
transform.position = transform.position + new Vector3(0.64f, 0);
//Here's the problem VVV
GameObject tilepos = Instantiate(seed.Substring(seedSub * 4 - 3, 4)) as GameObject;
//Here's the problem ^^^
tilepos.transform.position = new Vector2(transform.position.x, transform.position.y);
}
}
}
}```