unity 5.0之后不支持AddComponent(string)
以下为核心代码:
private static Dictionary<string, Type> types = new Dictionary<string, Type>();
public static EnemyPlane AddPlaneAI(GameObject go, string operate){
EnemyPlane enemy = null;
Type ttt =null;
if (types.ContainsKey(operate)) {
ttt = types[operate];
}
else
{
ttt = Type.GetType(operate);
}
Component component = go.AddComponent(ttt);
if (component != null)
enemy = component as EnemyPlane;
return enemy;
}