I have a script, that should submit a string to another script. I did this so many times before, but now I just don’t know where the mistake is, the string is not submitted at all…
Here’s the submitting code, attached to a button:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DILDMainButton : MonoBehaviour {
private GameObject SubMenu;
private string Infotext;
public string TextWindowText;
void Awake()
{
SubMenu = transform.FindChild("SubMenu").gameObject;
Infotext = this.GetComponent<Infotext>().InfoText;
TextWindowText = GameObject.Find("TextWindowText").GetComponent<TextWindow>().CurrentText;
}
void Start()
{
print(GameObject.Find("TextWindowText").transform.parent.name);
print(TextWindowText);
}
public void OnCursorIn()
{
TextWindowText = Infotext;
print(TextWindowText);
}
public void OnCursorOut()
{
TextWindowText = "";
}
public void GetEnabled()
{
SubMenu.SetActive(true);
foreach (Transform Button in transform.parent)
{
if (Button != transform)
{
SendMessage("GetDisabled()", false, SendMessageOptions.DontRequireReceiver);
}
}
}
public void GetDisabled()
{
SubMenu.SetActive(false);
}
}
Here’s the script that should receive the string:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class TextWindow : MonoBehaviour
{
public string CurrentText;
private string DefaultText;
void Awake()
{
DefaultText = this.GetComponent<Text>().text;
CurrentText = DefaultText;
}
void Start()
{
print(CurrentText);
}
void Update()
{
this.GetComponent<Text>().text = CurrentText;
}
}
Using the print function in the submitting script shows, that the other script is connected correctly:
print(GameObject.Find(“TextWindowText”).transform.parent.name);
print(TextWindowText);
TextWindowText == CurrentText, but shows just null from the Start() function. Shows the correct infotext when printed from OnCursorIn(), but without showing the text in the receiving script.