- Home /
How to Convert a Variable Name to a String?
I have a bunch of static variables in another script that I'd like to access. I'd like to be able to tell if a string has the same name as the other variable. For example, if the other script was called script1 and the variable was called variable1:
var words : String;
function Start(){
if(words == script1.variable1){
Destroy(gameObject);
}
}
How would I make it so the name of the variable could be converted into a string?
Comment
Answer by triangle4studios · Jan 26, 2021 at 06:10 AM
No no no!
Name of, is the correct way to get variables as a string.
https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/operators/nameof