Hello!
I declare a dinamic array but I dont know how to define its elements
private var frames: Texture[];
function Awake()
{
for(i=1;i<29;i++) frames.Add(GetComponent("fart_"+i.ToString())); //dont work
}
Hello!
I declare a dinamic array but I dont know how to define its elements
private var frames: Texture[];
function Awake()
{
for(i=1;i<29;i++) frames.Add(GetComponent("fart_"+i.ToString())); //dont work
}
Try this
private var frames: Texture[];
function Awake()
{
for(i=1;i<29;i++) frames[i] = GetComponent("fart_"+i.ToString());
}
Disclaimer: Untested code.
You also need to create the array itself. Arrays declared with [ ] are static arrays and can only be of fixed size.
(Also note that arrays are indexed from 0 not 1;
private var frames: Texture[];
function Awake()
{
frames = new Texture[28]; // Array can hold 28 entries: 0..27
for(i=0;i<28;i++)
frames[i] = GetComponent("fart_"+(i+1).ToString());
}
Thanks a lot!
There is a working version:
private var frames: Texture[];
function Awake()
{
frames = new Texture[28]; // Array can hold 28 entries: 0..27
for(i=0;i<28;i++)
frames[i] =Resources.Load("smiles/fart/fart_"+(i+1).ToString());
}