So im trying to make a if statement with a ui button in Uinty and i need to get the name of the button for the if state ment but it tells me that it is not convertabel even thou it is bouth a string or is it not?
I tried it like this and was expecting it to work but it didn´t
public class UIGetClick : MonoBehaviour
{
public bool clicked = false;
public string ButtonName = EventSystem.current.currentSelectedGameObject.name;
public void Back()
{
string ClickedButtonName = EventSystem.current.currentSelectedGameObject.name;
}
public void Freez()
{
if (ButtonName = "Back")
{
clicked = true;
}
else
{
clicked = false;
}
Debug.Log(clicked);
}
}
Assets\UIGetClick.cs(18,13): error CS0029: Cannot implicitly convert type 'string' to 'bool'
I also tried bool.
and string.
but that didn´t work either.
public class UIGetClick : MonoBehaviour
{
public bool clicked = false;
public string ButtonName = EventSystem.current.currentSelectedGameObject.name;
public void Back()
{
string ClickedButtonName = EventSystem.current.currentSelectedGameObject.name;
}
public void Freez()
{
if (ButtonName == "Back")
{
clicked = true;
}
else
{
clicked = false;
}
Debug.Log(clicked);
}
NullReferenceException: Object reference not set to an instance of an object UIGetClick..ctor () (at Assets/UIGetClick.cs:9)
any thoughs and help?