- Home /
Question by
bobor20001 · Aug 01, 2014 at 10:00 PM ·
boolpublicpublic static
Problem with creating static bool...
I can't call this:
using UnityEngine;
using System.Collections;
public static class VarToUtilities {
public static bool StringToBool(this string RecievedText) {
if(RecievedText == "true"){
return true;
}else if(RecievedText == "True"){
return true;
}else if(RecievedText == "false"){
return false;
}else if(RecievedText == "False"){
return false;
}else if(RecievedText == "no"){
return false;
}else if(RecievedText == "No"){
return false;
}else if(RecievedText == "yes"){
return true;
}else if(RecievedText == "Yes"){
return true;
}
return false;
}
}
with this code:
using UnityEngine;
using System.Collections;
public class Tester : MonoBehaviour {
public string ExampleString;
public bool ExampleBool;
void Update () {
ExampleBool = StringToBool(ExampleString);
}
}
How to get this work? Please help!
Comment
In your Tester
class, there's no function StringToBool
.
There is a function VarToUtilities.StringToBool
. You need to fully qualify the name.
Then you have to move the StringToBool
method into the Tester
class...
as written, your StringToBool()
method can be rewritten as:
public static class VarToUtilities
{
public static bool StringToBool(this string recievedText)
{
var lowerCaseText = recievedText.ToLower();
return ((lowerCaseText == "true") || (lowerCaseText == "yes"));
}
}
Best Answer
Answer by rutter · Aug 02, 2014 at 06:37 AM
As explained in comments, you need a fully qualified name:
ExampleBool = VarToUtilities.StringToBool(ExampleString);