I have a CO class, an equipment class, and a switchboard class which inherits from equipment,
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class CO2 {
public List<EQUIPMENT> equipments;
public List<PERSONNEL> personnel;
public Vector2 position;
public string coLabel ;
public CO2 (string co_label,Vector2 my_pos, List<EQUIPMENT> _equipments = null, List<PERSONNEL> _personnel = null)
{
coLabel=co_label;
this.equipments = _equipments == null ? new List<EQUIPMENT>() : _equipments;
this.personnel = _personnel == null ? new List<PERSONNEL>() : _personnel;
position= my_pos;
}
public CO2 ()
{
equipments=null;
personnel=null;
position= new Vector2 (0,0);
coLabel=null;
}
public void AddEquipment( EQUIPMENT newequipment )
{
this.equipments.Add (newequipment);
}
public void AddPersonnel( PERSONNEL newpersonnel )
{
this.personnel.Add (newpersonnel);
}
}
using UnityEngine;
using System.Collections;
public class EQUIPMENT {
public Transform obj;
public Vector3 obj_pos;
public int maintenence_cost;
public int max_subs;
public EQUIPMENT ()
{
obj = null;
obj_pos = new Vector3(0,0,0);
maintenence_cost = 123;
max_subs=123;
}
public EQUIPMENT (Transform new_object, Vector3 new_object_pos, int new_cost, int new_max_subs)
{
obj = new_object;
obj_pos = new_object_pos;
maintenence_cost = new_cost;
max_subs=new_max_subs;
}
}
using UnityEngine;
using System.Collections;
public class SWITCHBOARD : EQUIPMENT {
public SWITCHBOARD (Transform new_object, Vector3 new_object_pos)
{
maintenence_cost = 1160;
max_subs=52;
}
}
in my main script I have this
city.centralOffice.AddEquipment (new EQUIPMENT (test_prefab, Newposition, test_maintenence_cost, 10000));
city.centralOffice.AddEquipment (new SWITCHBOARD (switchboard_prefab, Newposition));
Elsewhere in the main script I have this
foreach (EQUIPMENT e in city.centralOffice.equipments) {
Instantiate (e.obj, e.obj_pos, transform.rotation);
it works fine for the test_prefab but for switchboard_prefab I get error
ArgumentException: The thing you want to instantiate is null