I have tried many times to fix this without success. Whenever I close my function on line 14 (public void FrenchButton ()
), it thinks it closes public class LanguageMenuScript : MonoBehaviour
. How can I fix this?
The code is below:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class LanguageMenuScript : MonoBehaviour
{
public Text languageTitleText;
public void FrenchButton()
{
public string language = "French";
}
void Start (){
Text.text = Language;
}
void Update()
{
if (language == "French")
{
languageTitleText.text = "Langue";
}
}
}
You have public string language = "French"; inside a function. You can't have a access modifier inside a function and you cant access variables declared inside a function from outside. What you want to do there is declare it next to languageTitleText inside the class scope. you can then assign a value in your FrenchButton function if you want -> language = "French"; for instance.