- Home /
Initialize method parameter
I know it's possible to initialize some parameters so that they'll use that value if it isn't specified when the method is called, for example
public void SomeMethod(bool someBool = true)
{
}
But it doesn't seem to work with some types such as colors, is there a way to initialize a color parameter?
public void SomeMethod(Color someColor = new Color(1,1,1,1))
{
//This doesn't work
}
Comment
Best Answer
Answer by Bunny83 · Oct 07, 2018 at 10:49 PM
No it isn't because default parameters need to be constant expressions. You have to create a method overload
public void SomeMethod(Color someColor)
{
// [ ... ]
}
public void SomeMethod()
{
SomeMethod(new Color(1,1,1,1));
}
Your answer
Follow this Question
Related Questions
Changing character colour on code 1 Answer
Assigning current color to a variable for fade out (C#) 0 Answers
Toggle Boolean Function 2 Answers
Accessing variable from a method in another script and gameObject 2 Answers
Comparing 2 color variables. 1 Answer