Ejemplo n.º 1
0
    /*
     * Instanciate a item
     */
    private void InstanciateItem(Map map, Item item, Vector3 position)
    {
        List <Spawnable> listItems = this._spawnables [map];

        GameObject obj     = GameObject.Instantiate <GameObject> (this.prefabSpawnable.gameObject);
        ItemObject newItem = obj.GetComponent <ItemObject> ();

        newItem.Item = item;
        newItem.name = item.name;
        newItem.GetComponentInChildren <SpriteRenderer> ().sprite = item.Sprite;
        newItem.gameObject.SetActive(false);
        newItem.gameObject.transform.position = new Vector3(position.x, position.y, 0.0f);
        listItems.Add(newItem);
        // Update
        this._spawnables [map] = listItems;
        this._nbrSpawnables++;

        Debug.Log("Add Item on map : " + map.MapID);

        // if map active => spawn item
        if (MeshMap.Instance.IsReady && MeshMap.Instance.CurrentMap.Equals(map))
        {
            Spawn(newItem);
        }
    }