I have a mistake that says that it doesn't see the text I tried everything and Idk what to do :(

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;
public class GateGenerator : MonoBehaviour
{
public GameObject goodGatePrefab;
public GameObject badGatePrefab;
public TextMeshPro goodGateText;
public TextMeshPro badGateText;
public int numberOfRows = 5;
public int pairsPerRow = 3;
public float gapBetweenPairs = 2f;
public float gapBetweenRows = 2f;
[SerializeField] float multiplicationGateProbability = 0.3f;
[SerializeField] float divisionGateProbability = 0.3f;
[SerializeField] private TextRandomizer tr;
void Awake()
{
tr.GetComponent();
GameObject goodPanel = goodGatePrefab.transform.Find(“Cube”).gameObject;
GameObject badPanel = badGatePrefab.transform.Find(“Cube”).gameObject;
Canvas goodCanvas = goodPanel.GetComponentInChildren();
Canvas badCanvas = badPanel.GetComponentInChildren();
goodGateText = goodCanvas.GetComponentInChildren();
badGateText = badCanvas.GetComponentInChildren();
}
void Start()
{
GenerateRows();
}
void GenerateRows()
{
Vector3 spawnPosition = transform.position;
for (int i = 0; i < numberOfRows; i++)
{
SpawnRow(spawnPosition);
spawnPosition.z += gapBetweenRows;
}
}
void SpawnRow(Vector3 spawnPosition)
{
Vector3 pairSpawnPosition = spawnPosition;
for (int i = 0; i < pairsPerRow; i++)
{
SpawnPair(pairSpawnPosition);
pairSpawnPosition.x += gapBetweenPairs * 3;
}
}
void SpawnPair(Vector3 pairSpawnPosition)
{

GameObject firstGate = Random.Range(0f, 1f) < 0.5f ? goodGatePrefab : badGatePrefab;
if (firstGate == goodGatePrefab && Random.Range(0f, 1f) < multiplicationGateProbability)
{
tr.MultiplyRandom();
int MultiplyingVar = tr.mr;

goodGateText.text = “x” + MultiplyingVar.ToString();
Instantiate(goodGatePrefab, pairSpawnPosition, Quaternion.identity, transform);
}
else if (firstGate != goodGatePrefab && Random.Range(0f, 1f) < divisionGateProbability)
{
tr.DivideRandom();
int dividingVar = tr.dr;

badGateText.text = “÷” + dividingVar.ToString();
Instantiate(badGatePrefab, pairSpawnPosition, Quaternion.identity, transform);
}
else
{
// Instantiate the chosen gate
Instantiate(firstGate, pairSpawnPosition, Quaternion.identity, transform);
}
pairSpawnPosition.x += gapBetweenPairs;

GameObject secondGate = Random.Range(0f, 1f) < 0.5f ? goodGatePrefab : badGatePrefab;
if (secondGate == goodGatePrefab && Random.Range(0f, 1f) < multiplicationGateProbability)
{
tr.MultiplyRandom();
int MultiplyingVar = tr.mr;
goodGateText.text = “x” + MultiplyingVar.ToString();
Instantiate(goodGatePrefab, pairSpawnPosition, Quaternion.identity, transform);
}
else if (secondGate != goodGatePrefab && Random.Range(0f, 1f) < divisionGateProbability)
{
tr.DivideRandom();
int dividingVar = tr.dr;

badGateText.text = “÷” + dividingVar.ToString();
Instantiate(badGatePrefab, pairSpawnPosition, Quaternion.identity, transform);
}
else
{
Instantiate(secondGate, pairSpawnPosition, Quaternion.identity, transform);
}
}
}

My gate prefab has a cube on it which has a canvas which has text:

9768336--1399551--1.png

Please use the code tags.
You have:

tr.GetComponent<TextRandomizer>();

It doesn’t do anything. Should it be?

tr = GetComponent<TextRandomizer>();
1 Like

Speaking of text, when I go closer to TMP text it disappears.

Decrease your Camera near clip plane