Hi everyone, I have been trying to create a way to add strings to a string array. Basically what I’m trying to do is when either button1, button2, button3, or button4 are clicked they add either button1, button2, button3, or button4 to text2’s string array depending on what button was clicked. Any idea how to do this? I tried typing in Text2.Add(new string(Text[a])); but I got an error from unity saying that type string does not contain a definition for add.
using UnityEngine;
using System.Collections;
public class ExampleScript : MonoBehaviour {
public string[] Text;
public string[] Text2;
void OnGUI(){
Text = new string[]{"Button1", "Button2", "Button3", "Button4"};
GUILayout.BeginArea(new Rect(Screen.width/3.5f, Screen.height/4,Screen.width, Screen.height));
GUILayout.BeginHorizontal();
scrollPosition = GUILayout.BeginScrollView (scrollPosition, GUILayout.Width (125), GUILayout.Height (125));
for (int a = 0; a < Text.Length; a++){
if (GUILayout.Button(Text[a], GUILayout.Width(125), GUILayout.Height(25)))
{
//error type string[] does not contain definition for add
Text2.Add(new string(Text[a]));
}
}