Cant convert String to Text.

So I’m new to coding and I’m trying to make a mobile app that insults you with old insults and I’m trying to make it pick a random insult from three columns and put them together but I’m having problems in unity

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class ShakespeareanInsultKit : MonoBehaviour
{
public string[ ] columnOne;

public string[ ] columnTwo;

public string[ ] columnThree;

public Text Column1;
public Text Column2;
public Text Column3;

int index;

public void Insult()
{

index1 = Random.Range (0,columnOne.Length);
insult1 = columnOne[index1];
index2 = Random.Range (0, columnTwo.Length);
insult2 = columnTwo[index2];
index3 = Random.Range (0, columnThree.Length);
insult3 = columnThree[index3];
Text CompleteInsult = gameObject.GetComponent();
Column1.text = insult1;

}

}

That’s the code and unity keeps saying that index and insults do not exist any help?

  1. Use code tags to make your code readable
  2. you never declared any of the variables you used, isn‘t your editor glowing red? You only declared ‚index‘ as an int. Then you proceed to assign index1, index2, index3 and insults although they do not even exist.
1 Like

First of all, "ShakespeareanInsultKit " is dope name, haha (in the good way)

It tells you that the index1/2/3 don’t exist because you haven’t declared them anywhere

int index1 = Random.Range (0,columnOne.Length);
string insult1 = columnOne[index1];
//etc.

tells the code create an int called index1 and set it to blah blah blah
all you did is tell the code to set index to blah so he’s telling you you don’t have anything called index1
same goes for the strings

1 Like