// void removeWeapon() { if (weapons.Count != 0) { string LastAdded = weapons[w.wep.Count - 1]; // // 1 // GameObject FindLastAdded = GameObject.Find("" + LastAdded); DestroyImmediate(FindLastAdded); // // 2 // activeWeap = FindObjectOfType <ActiveWeapons>(); // Reference to ActiveWeapons. activeWeap.Weapons.RemoveAt(activeWeap.Weapons.Count - 1); // Remove weapon from ActiveWeapons List startWeap = FindObjectOfType <StartWeapons>(); // Reference to StartWeapons. startWeap.Weapons.RemoveAt(startWeap.Weapons.Count - 1); // Remove weapon from StartWeapons List GameObject FindLastAddedOnPanel = GameObject.Find("" + LastAdded); DestroyImmediate(FindLastAddedOnPanel); weapons.RemoveAt(weapons.Count - 1); } }
// void createWeapon() { // // 1 // // creating new "Weapon" Gameobject, parent it to weapon selection and add weaponMobile component. g = new GameObject("" + weaponName); g.AddComponent <weaponHolder>(); if (WeaponImage) { g.GetComponent <SpriteRenderer>().sprite = WeaponImage; } W = GameObject.FindWithTag("WeaponSelection");// finding weaponSelection to parent new weapon to it. g.transform.SetParent(W.transform); // // create new GameObject and parent it to weapon. p = new GameObject("GameObject"); p.transform.SetParent(g.transform); // // add name to new weapon string www = weaponName; g.name = www; weapons.Add(g.name); // add new weapon to "Weapons" ScriptableObject. // // 2 // //adding new new Weapon on weapons panel. // creating new "Weapon" Gameobject, parent it to weapon panel and add Button and Image components. b = new GameObject("" + weaponName); b.AddComponent <Image>(); b.GetComponent <Image>().sprite = WeaponImage; b.AddComponent <Button>(); b.layer = 5; GameObject weaponpanel = GameObject.Find("Panel");// finding weapon Panel to parent new weapon to it. b.transform.SetParent(weaponpanel.transform); b.transform.localScale = new Vector3(1, 1, 1); // // create new Text GameObject and parent it to weapon. string[] results2 = AssetDatabase.FindAssets("_Weapons"); string ScriptableObjectpath = AssetDatabase.GUIDToAssetPath(results2[0]); w = (Weapons)AssetDatabase.LoadAssetAtPath(ScriptableObjectpath, typeof(Weapons)); pb = new GameObject(weaponName + "Ammo"); pb.transform.SetParent(b.transform); pb.AddComponent <Text>(); Text text = pb.GetComponent <Text>(); text.font = w.MainFont; text.fontSize = 30; text.color = new Color32(50, 50, 50, 255); text.alignment = TextAnchor.MiddleCenter; pb.layer = 5; RectTransform TEXTrect = pb.GetComponent <RectTransform>(); TEXTrect.localScale = new Vector3(1, 1, 1); TEXTrect.anchorMin = new Vector2(0.6187f, 0f); TEXTrect.anchorMax = new Vector2(1, 1); TEXTrect.offsetMin = new Vector2(0, 0); TEXTrect.offsetMax = new Vector2(20, 0); // activeWeap = FindObjectOfType <ActiveWeapons>(); // Reference to ActiveWeapons. activeWeap.Weapons.Add(b); // Add Weapon to Activeweapons List. weaponIndex = activeWeap.Weapons.Count - 1; startWeap = FindObjectOfType <StartWeapons>(); // Reference to StartWeapons. startWeap.Weapons.Add(b); // Add Weapon to Activeweapons List. // Button butten = b.GetComponent <Button>(); WeaponSelection waepsel = FindObjectOfType <WeaponSelection>(); UnityAction <int> action = new UnityAction <int>(waepsel.Select); UnityEventTools.AddIntPersistentListener(butten.onClick, action, weaponIndex); GameManager gameManager = FindObjectOfType <GameManager>(); gameManager.WeaponsDamage.Add(weaponDamage); }
// void createWeaponFromPrefab() { pre = Instantiate(prefab, new Vector3(0, 0, 0), Quaternion.identity) as GameObject; pre.name = prefab.name; weapons.Add(pre.name); // add new weapon to "Weapons" ScriptableObject. W = GameObject.FindWithTag("WeaponSelection"); // finding weaponSelection to parent new weapon to it. pre.transform.SetParent(W.transform); // // instantiate weapon prefab and parent it to weapon. // 2 // //adding new new Weapon on weapons panel. // creating new "Weapon" Gameobject, parent it to weapon panel and add Button and Image components. b = new GameObject("" + pre.name); b.AddComponent <Image>(); if (WeaponImage) { b.GetComponent <Image>().sprite = WeaponImage; b.GetComponent <Image>().preserveAspect = true; } b.AddComponent <Button>(); b.layer = 5; //Debug.Log("2"); GameObject weaponpanel = GameObject.Find("Panel");// finding weapon Panel to parent new weapon to it. b.transform.SetParent(weaponpanel.transform); b.transform.localScale = new Vector3(1, 1, 1); // // create new Text GameObject and parent it to weapon. pb = new GameObject(pre.name + "Ammo"); Debug.Log("3"); pb.transform.SetParent(b.transform); pb.AddComponent <Text>(); Debug.Log("4"); Text text = pb.GetComponent <Text>(); text.font = w.MainFont; text.fontSize = 30; text.color = new Color32(50, 50, 50, 255); text.alignment = TextAnchor.MiddleCenter; pb.layer = 5; RectTransform TEXTrect = pb.GetComponent <RectTransform>(); TEXTrect.localScale = new Vector3(1, 1, 1); TEXTrect.anchorMin = new Vector2(0.6187f, 0f); TEXTrect.anchorMax = new Vector2(1, 1); TEXTrect.offsetMin = new Vector2(0, 0); TEXTrect.offsetMax = new Vector2(20, 0); // activeWeap = FindObjectOfType <ActiveWeapons>(); // Reference to ActiveWeapons. activeWeap.Weapons.Add(b); // Add Weapon to Activeweapons List. weaponIndex = activeWeap.Weapons.Count - 1; startWeap = FindObjectOfType <StartWeapons>(); // Reference to StartWeapons. startWeap.Weapons.Add(b); // Add Weapon to Activeweapons List. // Button butten = b.GetComponent <Button>(); WeaponSelection waepsel = FindObjectOfType <WeaponSelection>(); UnityAction <int> action = new UnityAction <int>(waepsel.Select); UnityEventTools.AddIntPersistentListener(butten.onClick, action, weaponIndex); GameManager gameManager = FindObjectOfType <GameManager>(); gameManager.WeaponsDamage.Add(weaponDamage); }