- Home /
[SOLVED]How to use attributes from array of custom class instances?
Hey guys, well it seems that I moved on but I dont understand how to access to instances of the class. I will explain.
public Waves[] LevelName = new Waves[3];
This creates 3 instances of class Waves, I can see them in the inspector so it means I can work with them and edit them but what if I want to display the name on the player's screen of first instance (wave) how to approach it ?
Or if I want to spawn a unit that inherits attributes from wave. e.g. I want to spawn unit that gets hp, armor, movespeed and model from instance (certain wave) and simultaneously display on the screen the name of level (attribute of wave). Is there a way how to do it please?
using UnityEngine;
using System.Collections;
public class NewSpawnScript : MonoBehaviour {
public enum ArmorType {unarmored, light, medium, heavy}
[System.Serializable]
public class Waves {
public string waveName;
public int numberOfUnits;
public GameObject model;
public int hp;
public ArmorType armor;
public int movespeed;
}
public Waves[] LevelName = new Waves[3];
}
[EDITED]
Solution was quite simple I was using wrong typed command, thats why it didnt work. For other people usage: e.g.
Debug.Log(LevelName[IndexOfInstance].armor);
Answer by Jeff-Kesselman · Jun 11, 2014 at 09:51 PM
If you want the instancing to happen s the result of settings in the editor and not at run time, you need to make a custom inspector.
See http://unity3d.com/learn/tutorials/modules/intermediate/editor/building-custom-inspector
and
I've figured out how to set the size of instances in script or in inspector but now I dont know how to approch them. Please see the edited question above. Btw. thanks for reply :)