问题描述
从我读这是怎样一个向量大小设置为
From what I have read this is how a vector "Size" is set
public Color[] teamAColors = new Color[4];
但在运行code时,它看起来像这样
这似乎并不重要,我把什么号码为[4],大小始终保持6.我不知道那里的6号甚至我还没有设置任何东西,这个数字的到来。
It doesn't seem to matter what number I put for the [4], the Size always stays 6. I am not sure where the 6 number is even coming from as I have not set anything to that number.
我甚至试过
public Color[] teamAColors;
然后让我的数组自动填充长度,但这并不改变或者6
And then let my array auto populate the Length, but that doesn't change the 6 either.
推荐答案
,它只是
public Color[] teamAColors;
但你已经迷迷糊糊到RESETWOE!
BUT YOU'VE STUMBLED ON TO THE "RESET" WOE!
只是用不同的变量名称试试吧
Just try it with a different var name
public Color[] teste;
看?举例..
有它工作正常。您可以动态设置大小,只要你忽略了大小的定义。
There it is working fine. You can set the size dynamically, so long as you omit the size in the definition.
团结持有至连载值就比较复杂了。
Unity "holds on to" serialized values in a complicated way.
您可以修复这个..查找的著名微小的复位按钮... 的附着在细小齿轮象征。
You can fix this .. look for the famous tiny reset button ... attached to the tiny Cog symbol.
这是值得记住的是,作为一项规则,如果你有一个公共变量,
It's worth remembering that, as a rule, if you have a public variable,
public float x; // do this
不要设置默认,在code值。
don't set a "default" value in the code ..
public float x=2f; // generally NEVER DO THIS
下面是一个令人难以置信的方便的窍门。试试这个...
Here's an incredibly handy trick. Try this ...
[Header("How good is this?")]
public float x;
下面是一个更酷的!试试吧!
Here's an even cooler one! try it!
[Range(2f,4f)]
public float x;
这篇关于无法更改数组大小在检查变量在Unity?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!