Unity 在这种情况下显示错误。如何将这些参数标记为“可选”,或者是否有更好的解决方案?
示例:
void example(Texture texture1, Texture texture2, Texture texture3, Texture texture4) {
renderer1.material.mainTexture = texture1;
if (texture2 != null) {
renderer2.material.mainTexture = texture2;
}
if (texture3 != null) {
renderer3.material.mainTexture = texture3;
}
if (texture4 != null) {
renderer4.material.mainTexture = texture4;
}
}
public void callExample(){
example(texture1, texture2);
};
答案 0 :(得分:1)
要使参数可选,您应该提供默认值,就像这样:
void example(Texture texture1, Texture texture2 = null, Texture texture3 = null, Texture texture4 = null) {