- Home /
Serialized Array: Trying to wrap my head around it
So I am trying a serialized array used for selecting weapons. What's the proper way to call or set that info from a method?
I've seen it working with a "for" loop and an "if (Input.GetKeyDown)" - but I'd like to change weapons based on collision, and am hoping to do that via subclass & overriding on a separate object you collide with.
public GunDefinition[] guns;
public int selectedGun;
[System.Serializable]
public class GunDefinition
{
public GunLauncher launcher;
}
public virtual void GunChooser (){
for (int i = 0; i < guns.Length; i++) {
// this doesn't work
selectedGun = 1;
}
}
Answer by gurjmatharu · Apr 07, 2017 at 11:34 PM
I'm not quite sure if I understand the question.
But If you want to iterate through the array it needs to be initialised with 'new'
var array = new GunDefinition[]
Then you should be able to iterate.
Your answer
Follow this Question
Related Questions
C#-XMLSerialize a Struct with Vector3 Array in it 2 Answers
Why is my C# array of objects fully populated when some of them should be null? 3 Answers
Array not updating in inspector 0 Answers
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers