- Home /
How to access a public string attached on a UI Button
I need to access the public string variable on the script that is attached on my UI button and also to concatenate it.
Just to be clear this is for a word game, I have 26 buttons that contains letters from A - Z and each button has its own string value for the letter (example: Button A has a string value of "a"). Then i want to concatenate the string values whenever the player is trying to create a word.
using UnityEngine;
using UnityEngine.UI;
public class LetterTiles : MonoBehaviour {
public string letter;
public Text displayer;
float addTime;
string word;
public GameObject tile;
GameObject Tile;
Vector3 scale = new Vector3(0.8f, 0.8f, 0);
public void letterClick()
{
//wordBuild.currentWord += GetComponent(Type.GetType(letter));
wordBuild.currentWord += GetComponent(letter);
//wordBuild.currentWord += GetComponent<Button>;
Debug.Log(wordBuild.currentWord);
}
}
Answer by GreenSerpent · Nov 26, 2018 at 02:36 AM
I'm not too sure what you are trying to do, but it looks like you are trying to add the letter
string to the wordBuild.currentWord
string. I believe the correct way to do this is with wordBuild.currentWord += letter;
Your answer
Follow this Question
Related Questions
Split string in C#? 1 Answer
Getting GameCenter username to string? 1 Answer
GUI buttons referencing wrong object. 0 Answers
how to change a gui button texture 1 Answer
Passing a Script Name to a Function 2 Answers