// Create a GameObject in the map by data in the passed Map.Unit public UI.MapUnitUI GetGameObjectClone(Map.Unit mapUnit) { if (!prefabs.ContainsKey(mapUnit.CoreUnit.Type.ToString())) { Debug.Log("Warning! No GameObject was generated because of type error!"); return(null); } GameObject clonedGameObject = GameObject.Instantiate(prefabs[mapUnit.CoreUnit.Type.ToString()] as GameObject, mapUnit.Position, mapUnit.Rotation); MapUnitUI clonedMapUnitUI = clonedGameObject.AddComponent <MapUnitUI>(); clonedMapUnitUI.SendMessage("SetMapUnit", mapUnit, SendMessageOptions.RequireReceiver); return(clonedMapUnitUI); }
// Add Map.Unit to this script public void SetMapUnit(Map.Unit mapUnit) { this.mapUnit = mapUnit; }