- Home /
Why can't I to declare public the variable "Clave"?
string Clave = "1234";
int[] accesos = { 0, 0, 0 };
switch(Clave)
{
case "1234":
accesos[0]++;
print("Usuario ha accedido");
break;
case "3141":
accesos[1]++;
print("Editor ha accedido");
break;
case "8007":
accesos[2]++;
print("Administrador ha accedido");
break;
default:
print("Acceso denegado");
break;
}
I think more explanation is needed..
What is wrong here exactly? This code looks rather fine.. There's nothing wrong with it..
If you mean that when you try to write public string Clave
it marks it with red line, meaning compiling error, you should either read it, and if you don't understand it, you can post it here.
Also where is this piece of code sitting?
Answer by The-Peaceful · May 02, 2021 at 07:32 AM
Looks to me like the variable is in a method. A variable inside a method can't be declared public, because it can be used only in the method itself. So you just write it outside of the method (in the class itself) and then declare it as a public variable.
Your answer
Follow this Question
Related Questions
Making a variable work in two separate objects? 4 Answers
What is the difference between 'public var' and 'var' when declaring variables? 3 Answers
How to make variable accessible by other scripts but not visible in editor? 1 Answer
public script variable in inspector 2 Answers
Can I declare a variable inside a function which has instance scope? 1 Answer