public void SpawnItem() { if (GetCurrentlySelectedTab() == 0 && PlayerManager.instance.GetComponent <PlayerStats>().CheckPoints(OnlineTable.Ammo[CurrentlySelectedItem].Price)) { PlayerManager.instance.GetComponent <PlayerStats>().UsePoints(OnlineTable.Ammo[CurrentlySelectedItem].Price); GameObject Item = (GameObject)Instantiate(OnlineTable.Ammo[CurrentlySelectedItem].Item.GetComponent <Drag_Inventory>().ItemOnDrop); Item.transform.SetParent(GameObject.FindWithTag("Items_Spawn_Here").transform); Item.name = OnlineTable.Ammo[CurrentlySelectedItem].Item.GetComponent <Drag_Inventory>().ItemOnDrop.name; Vector3 tempPos = SpawnPoint.transform.position; Item.transform.position = new Vector3(tempPos.x, tempPos.y + 0.50f, tempPos.z); if (OnlineTable.Ammo[CurrentlySelectedItem].Item.GetComponent <ItemStats>() && Item.transform.GetChild(0).GetComponent <Gun_Behaviour>()) { OdinTables.WeaponStatsTable FromStats = OnlineTable.Ammo[CurrentlySelectedItem].Item.GetComponent <ItemStats>().itemStats; OdinTables.WeaponStatsTable ToStats = Item.transform.GetChild(0).GetComponent <Gun_Behaviour>().Stats; ToStats.SetStats(FromStats, ToStats); } //Instantiate the Agent so that it will send to the other clients Agent tempAgent; if (Item.GetComponent <Agent>()) { tempAgent = Item.GetComponent <Agent>(); } else { Item.gameObject.AddComponent <Agent>(); tempAgent = Item.GetComponent <Agent>(); } tempAgent.AgentNumber = ID_Table.instance.ItemList[0]; ID_Table.instance.ItemList.RemoveAt(0); tempAgent.RepeatEvery = 10.0f; tempAgent.SendInstantiate(Item.transform.position); } else if (GetCurrentlySelectedTab() == 1 && PlayerManager.instance.GetComponent <PlayerStats>().CheckPoints(OnlineTable.Parts[CurrentlySelectedItem].Price)) { PlayerManager.instance.GetComponent <PlayerStats>().UsePoints(OnlineTable.Parts[CurrentlySelectedItem].Price); GameObject Item = (GameObject)Instantiate(OnlineTable.Parts[CurrentlySelectedItem].Item.GetComponent <Drag_Inventory>().ItemOnDrop); Item.transform.SetParent(GameObject.FindWithTag("Items_Spawn_Here").transform); Item.name = OnlineTable.Parts[CurrentlySelectedItem].Item.GetComponent <Drag_Inventory>().ItemOnDrop.name; Vector3 tempPos = SpawnPoint.transform.position; Item.transform.position = new Vector3(tempPos.x, tempPos.y + 0.50f, tempPos.z); if (OnlineTable.Parts[CurrentlySelectedItem].Item.GetComponent <ItemStats>() && Item.transform.GetChild(0).GetComponent <Gun_Behaviour>()) { OdinTables.WeaponStatsTable FromStats = OnlineTable.Parts[CurrentlySelectedItem].Item.GetComponent <ItemStats>().itemStats; OdinTables.WeaponStatsTable ToStats = Item.transform.GetChild(0).GetComponent <Gun_Behaviour>().Stats; ToStats.SetStats(FromStats, ToStats); } //Instantiate the Agent so that it will send to the other clients Agent tempAgent; if (Item.GetComponent <Agent>()) { tempAgent = Item.GetComponent <Agent>(); } else { Item.gameObject.AddComponent <Agent>(); tempAgent = Item.GetComponent <Agent>(); } tempAgent.AgentNumber = ID_Table.instance.ItemList[0]; ID_Table.instance.ItemList.RemoveAt(0); tempAgent.RepeatEvery = 10.0f; tempAgent.SendInstantiate(Item.transform.position); } else if (GetCurrentlySelectedTab() == 2 && PlayerManager.instance.GetComponent <PlayerStats>().CheckPoints(OnlineTable.Misc[CurrentlySelectedItem].Price)) { PlayerManager.instance.GetComponent <PlayerStats>().UsePoints(OnlineTable.Misc[CurrentlySelectedItem].Price); GameObject Item = (GameObject)Instantiate(OnlineTable.Misc[CurrentlySelectedItem].Item.GetComponent <Drag_Inventory>().ItemOnDrop); Item.transform.SetParent(GameObject.FindWithTag("Items_Spawn_Here").transform); Item.name = OnlineTable.Misc[CurrentlySelectedItem].Item.GetComponent <Drag_Inventory>().ItemOnDrop.name; Vector3 tempPos = SpawnPoint.transform.position; Item.transform.position = new Vector3(tempPos.x, tempPos.y + 0.50f, tempPos.z); if (OnlineTable.Misc[CurrentlySelectedItem].Item.GetComponent <ItemStats>() && Item.transform.GetChild(0).GetComponent <Gun_Behaviour>()) { OdinTables.WeaponStatsTable FromStats = OnlineTable.Misc[CurrentlySelectedItem].Item.GetComponent <ItemStats>().itemStats; OdinTables.WeaponStatsTable ToStats = Item.transform.GetChild(0).GetComponent <Gun_Behaviour>().Stats; ToStats.SetStats(FromStats, ToStats); } //Instantiate the Agent so that it will send to the other clients Agent tempAgent; if (Item.GetComponent <Agent>()) { tempAgent = Item.GetComponent <Agent>(); } else { Item.gameObject.AddComponent <Agent>(); tempAgent = Item.GetComponent <Agent>(); } tempAgent.AgentNumber = ID_Table.instance.ItemList[0]; ID_Table.instance.ItemList.RemoveAt(0); tempAgent.RepeatEvery = 10.0f; tempAgent.SendInstantiate(Item.transform.position); } }
public void SpawnItem(int FromEnemy, List <int> SpawnItem, Transform AtPosition) { //Go through all the Items that can spawn forn the spawn list for (int j = 0; j < SpawnItem.Count; j++) { //Go through all the Items that the Enemy can spawn for (int i = 0; i < Enemies[FromEnemy].Items.Count; i++) { //If the spawn list item is the same as the one the Enemy can spawn, than spawn it if (i == SpawnItem[j]) { //for (int k = 0; k < Enemies[FromEnemy].Items[i].Amount; k++) { // GameObject TempItem = Instantiate<GameObject>(Enemies[FromEnemy].Items[i].Item); // TempItem.name = Enemies[FromEnemy].Items[i].Item.name; // TempItem.transform.SetParent(GameObject.Find("World").transform.Find("Items").transform); // TempItem.transform.localPosition = AtPosition.localPosition; //} //Spawn the Item for (int k = 0; k < Enemies[FromEnemy].Items[i].Amount; k++) { GameObject TempItem = (GameObject)Instantiate(Enemies[FromEnemy].Items[i].Item); GameObject Item = (GameObject)Instantiate(TempItem.GetComponent <Drag_Inventory>().ItemOnDrop); Item.name = TempItem.GetComponent <Drag_Inventory>().ItemOnDrop.name; Item.transform.SetParent(GameObject.Find("World").transform.Find("Items").transform); Item.transform.localPosition = AtPosition.localPosition + new Vector3(0.0f, 0.5f, 0.0f); //Stuff happend and I dont need all of this, but keeping it any-way just in case. if (TempItem.GetComponent <ItemStats>() && Item.transform.GetChild(0).GetComponent <Gun_Behaviour>()) { OdinTables.WeaponStatsTable FromStats = TempItem.GetComponent <ItemStats>().itemStats; OdinTables.WeaponStatsTable ToStats = Item.transform.GetChild(0).GetComponent <Gun_Behaviour>().Stats; ToStats.SetStats(FromStats, ToStats); Item.transform.GetChild(0).GetComponent <Gun_Behaviour>().Stats = ToStats; } else if (TempItem.GetComponent <ItemStats>() && Item.transform.GetChild(0).GetComponent <ItemStats>()) { OdinTables.WeaponStatsTable FromStats = TempItem.GetComponent <ItemStats>().itemStats; OdinTables.WeaponStatsTable ToStats = Item.transform.GetChild(0).GetComponent <ItemStats>().itemStats; ToStats.SetStats(FromStats, ToStats); Item.transform.GetChild(0).GetComponent <ItemStats>().itemStats = ToStats; } else if (TempItem.GetComponent <Gun_Behaviour>() && Item.transform.GetChild(0).GetComponent <ItemStats>()) { OdinTables.WeaponStatsTable FromStats = TempItem.GetComponent <Gun_Behaviour>().Stats; OdinTables.WeaponStatsTable ToStats = Item.transform.GetChild(0).GetComponent <ItemStats>().itemStats; ToStats.SetStats(FromStats, ToStats); Item.transform.GetChild(0).GetComponent <ItemStats>().itemStats = ToStats; } else if (TempItem.GetComponent <Gun_Behaviour>() && Item.transform.GetChild(0).GetComponent <Gun_Behaviour>()) { OdinTables.WeaponStatsTable FromStats = TempItem.GetComponent <Gun_Behaviour>().Stats; OdinTables.WeaponStatsTable ToStats = Item.transform.GetChild(0).GetComponent <Gun_Behaviour>().Stats; ToStats.SetStats(FromStats, ToStats); Item.transform.GetChild(0).GetComponent <Gun_Behaviour>().Stats = ToStats; } Destroy(TempItem); //Instantiate the Agent so that it will send to the other clients Agent tempAgent; if (Item.GetComponent <Agent>()) { tempAgent = Item.GetComponent <Agent>(); } else { Item.AddComponent <Agent>(); tempAgent = Item.GetComponent <Agent>(); } tempAgent.AgentNumber = ID_Table.instance.ItemList[0]; ID_Table.instance.ItemList.RemoveAt(0); tempAgent.RepeatEvery = 10.0f; tempAgent.SendInstantiate(Item.transform.position); } } } } }