- Home /
Methods with Arguments (Noob Problem)
public string[] skills;
public float s1cooldowntime;
void Start () {
setCooldown(skills[1],s1cooldowntime);
}
public void setCooldown(string skillString, float skillTime){
switch(skillString){
case "1":skillTime=4.0f;break;
case "2":skillTime=4.5f;break;
}
}
it doesn't work, plesae help...
Comment
Best Answer
Answer by robertbu · Sep 28, 2014 at 12:15 PM
Floats are by value, so you doing:
skillTime = 4.0f;
...is only changing the local copy. You can fix the problem by using the 'out' keyword:
public void setCooldown(string skillString, out float skillTime){
...but it would be better to treat this as a function:
public string[] skills;
public float s1cooldowntime;
void Start () {
s1cooldowntime = setCooldown(skills[1]);
}
public float setCooldown(string skillString){
switch(skillString){
case "1": return 4.0f; break;
case "2": return 4.5f; break;
}
}
switch(skillString){
case "1": return 4.0f;
case "2": return 4.5f;
default: return 1.0f;
}
it's working now, thank you very much.
Your answer

Follow this Question
Related Questions
Why isn't the best overload method not compatible with the arguments list? 1 Answer
Error Using "0" as an argument in "SendMessage" 1 Answer
Argument out of Range 1 Answer
Static problem with opening custom editor window 1 Answer
The best overload for the method "XXXX" is not compatible with the arguement() 2 Answers