/// <summary> /// Create a new icon without reference in runtime. /// see all structure options in bl_MMItemInfo. /// </summary> public bl_MiniMapItem CreateNewItem(bl_MMItemInfo item) { if (hasError) { return(null); } GameObject newItem = Instantiate(ItemPrefabSimple, item.Position, Quaternion.identity) as GameObject; bl_MiniMapItem mmItem = newItem.GetComponent <bl_MiniMapItem>(); if (item.Target != null) { mmItem.Target = item.Target; } mmItem.Size = item.Size; mmItem.IconColor = item.Color; mmItem.isInteractable = item.Interactable; mmItem.m_Effect = item.Effect; if (item.Sprite != null) { mmItem.Icon = item.Sprite; } return(mmItem); }
/// <summary> /// Example of how create a item in run time without references /// just need a position where you need instantiate /// for sure are options for personalize the item /// see full structure for options in bl_MMItemInfo.cs /// </summary> void CreateItem() { //This just a example of a position where instantiate the item //in this example we will instantiate where input mouse is. Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit)) { Debug.DrawLine(ray.origin, hit.point, Color.red); //in this part we create a new item info //the most basic method is just send the (Vector3)position bl_MMItemInfo info = new bl_MMItemInfo(hit.point); //but you can customize this before send to create for eg: //info.Color = Color.white; //info.Size = 15; //info.Sprite = CustomSpriteReference; //se bl_MMItemInfo.cs for full options avaible. //Now send the info to the bl_MiniMap.cs reference for create it. MiniMap.CreateNewItem(info); //Done! } }