Hi , I was trying to implement multiple language to my game this codes take random upgrade and weapon part and respect to things that taken code takes taken things names damages , properties etc and set
text string with them but i couldn’t figure it out which part of this code does that. I started clean but near to the end my codes are getting out of control. I think it is about the function in line 304 GetRandomWeapon()
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;
using UnityEngine.Events;
using UnityEngine.EventSystems;
public class ExperienceBar : MonoBehaviour
{
public GameObject[] weaponSlots;
public static GameObject[] sweaponSlots;
static GameObject ContinueButton;
public static GameObject[] UpgradeLoc;
public static GameObject[] Upgrade;
public static GameObject[] AllUpgrades;
public static GameObject[] AllWeapons;
public GameObject[] allweapons;
public static GameObject[] Weapons;
public Button[] buttons;
public static Button[] Buttonss;
public GameObject[] AllUpgradesP;
public static int UpgradeNumber;
public static int WeaponNumber;
public static GameObject ExperienceBarInside;
public static Vector3 barsetter;
public static GameObject ExperienceBarText;
public GameObject bacgroundColor;
public static GameObject bacgroundColorS;
public GameObject weaponpart;
public static GameObject UpgradeMenu;
public static AudioSource audios;
public static AudioClip bell;
public AudioClip belll;
public static GameObject levelUpAnim;
static GameObject[] weaponParts;
WeaponHolder getWeaponForUnlock;
public List<GameObject> allWeaponParts;
public static List<GameObject> allWeaponPartsS;
public GameObject weaponsPartsFirst;
public static GameObject weaponsPartsFirstS;
public static int Level = 1;
void Start()
{
weaponsPartsFirstS = weaponsPartsFirst;
getWeaponForUnlock = GetComponent<WeaponHolder>();
allWeaponPartsS = allWeaponParts;
Level = 1;
CharacterStatsSetter.setCharacterStatsTexts();
sweaponSlots = new GameObject[4];
sweaponSlots = weaponSlots;
SetFalseWeaponSlots();
weaponParts = new GameObject[4];
buttons = new Button[4];
UpgradeLoc = new GameObject[4];
ContinueButton = GameObject.Find("ContinueButton");
ContinueButton.GetComponent<Button>().onClick.AddListener(GetRandomUpgrade);
ContinueButton.GetComponent<Button>().onClick.AddListener(DestroyLeftParts);
//Cursor.visible = false;
UpgradeNumber = AllUpgradesP.Length;
WeaponNumber = allweapons.Length ;
bacgroundColorS = bacgroundColor;
bacgroundColorS.SetActive(false);
for (int i = 0; i < 4; i++)
{
UpgradeLoc[i] = GameObject.Find("Upgrade_" + i);
}
for (int i = 0; i < 4; i++)
{
buttons[i] = UpgradeLoc[i].GetComponent<Button>();
}
AllWeapons = allweapons;
Buttonss = buttons;
levelUpAnim = GameObject.Find("LevelUpAnimation");
bell = belll;
audios = GetComponent<AudioSource>();
Upgrade = new GameObject[4];
Weapons = new GameObject[4];
AllUpgrades = AllUpgradesP;
UpgradeLoc = new GameObject[4];
for(int i = 0; i < 4; i++)
{
UpgradeLoc[i] = GameObject.Find("Upgrade_"+i);
}
UpgradeMenu = GameObject.Find("UgradeMenu");
ExperienceBarText = GameObject.Find("ExperienceBarText");
ExperienceBarInside = GameObject.Find("ExperienceBarİnside");
barsetter = ExperienceBarInside.transform.localScale;
barsetter.x = 0;
ExperienceBarInside.transform.localScale=barsetter;
UpgradeMenu.SetActive(false);
UnlockWeaponParts();
}
// Update is called once per frame
private void Update()
{
if (Input.GetKeyDown(KeyCode.L)) setExperienceBarInside();
}
void UnlockWeaponParts()
{
for (int index = 0; index < SetData.weaponsBool.Length; index++)
if (SetData.weaponsBool[index]) GetWholeWeapon(index+1);
}
void GetWholeWeapon(int index)
{
allWeaponPartsS.Add(getWeaponForUnlock.Cores[index]);
allWeaponPartsS.Add(getWeaponForUnlock.Bodies[index]);
allWeaponPartsS.Add(getWeaponForUnlock.Stocks[index]);
}
public static void setExperienceBarInside()
{
goldCoin();
if (barsetter.x >= 1f) // make 1
{
PauseMenu.isUpgradesTaken = false;
UpgradeMenu.SetActive(true);
ContinueButton.SetActive(true);
SetCursor.SetCursorVisibilityTrue();
bacgroundColorS.SetActive(true);
levelUpAnim.GetComponent<Animator>().Play("ExperienceAnim");
audios.PlayOneShot(bell,0.3f);
inGameControllerSupport.isLevelUp = true;
GetRandomWeapon();
WeaponCharacterChoice.timescal = 0;
barsetter.x = 0;
Level++;
ExperienceBarText.GetComponent<TMP_Text>().text = "Level " + Level;
}
ExperienceBarInside.transform.localScale = barsetter;
}
public static void GetRandomUpgrade()
{
for (int i = 0; i < 4; i++)// this resets the upgradelocs texts;
{
for (int child = 2; child < UpgradeLoc[i].transform.childCount; child++)
{
UpgradeLoc[i].transform.GetChild(child).GetComponent<TMP_Text>().text = null;
}
}
PartsCircuitsUpgradesStats.statsTexts getPartsStats;
for (int i = 0; i < 4; i++)
{
Color color = UpgradeLoc[i].transform.GetChild(0).GetComponent<Image>().color;
color.a = 1f;
UpgradeLoc[i].transform.GetChild(0).GetComponent<Image>().color = color;
/*
UpgradeLoc[i].transform.GetChild(2).GetComponent<TMP_Text>().text = "Damage >";
UpgradeLoc[i].transform.GetChild(3).GetComponent<TMP_Text>().text = "Cool down >";
UpgradeLoc[i].transform.GetChild(4).GetComponent<TMP_Text>().text = "Bullet num >";
UpgradeLoc[i].transform.GetChild(5).GetComponent<TMP_Text>().text = "Area >";
UpgradeLoc[i].transform.GetChild(6).GetComponent<TMP_Text>().text = "Crit Chance >";
UpgradeLoc[i].transform.GetChild(7).GetComponent<TMP_Text>().text = "Crit Damage >";
UpgradeLoc[i].transform.GetChild(8).GetComponent<TMP_Text>().text = "Pierce >";
UpgradeLoc[i].transform.GetChild(9).GetComponent<TMP_Text>().text = "Knock Back >";
*/
int random = Random.Range(0, UpgradeNumber);
Upgrade[i] = AllUpgrades[random];
UpgradeLoc[i].GetComponentInChildren<TMP_Text>().text = Upgrade[i].GetComponent<CardStats>().ExplanationTranslator();
UpgradeLoc[i].transform.GetChild(1).GetComponent<TMP_Text>().text = Upgrade[i].GetComponent<CardStats>().NameTranslator();
UpgradeLoc[i].transform.GetChild(0).GetComponent<Image>().sprite = Upgrade[i].GetComponent<CardStats>().ımage;
UpgradeLoc[i].GetComponent<CardStats>().attackSpeed = Upgrade[i].GetComponent<CardStats>().attackSpeed;
UpgradeLoc[i].GetComponent<CardStats>().Health = Upgrade[i].GetComponent<CardStats>().Health;
UpgradeLoc[i].GetComponent<CardStats>().damage = Upgrade[i].GetComponent<CardStats>().damage;
UpgradeLoc[i].GetComponent<CardStats>().Speed = Upgrade[i].GetComponent<CardStats>().Speed;
UpgradeLoc[i].GetComponent<CardStats>().armor = Upgrade[i].GetComponent<CardStats>().armor;
UpgradeLoc[i].GetComponent<CardStats>().Exp = Upgrade[i].GetComponent<CardStats>().Exp;
UpgradeLoc[i].GetComponent<CardStats>().criticalChance = Upgrade[i].GetComponent<CardStats>().criticalChance;
UpgradeLoc[i].GetComponent<CardStats>().criticalDamage = Upgrade[i].GetComponent<CardStats>().criticalDamage;
UpgradeLoc[i].GetComponent<CardStats>().Range = Upgrade[i].GetComponent<CardStats>().Range;
UpgradeLoc[i].GetComponent<CardStats>().knockBack = Upgrade[i].GetComponent<CardStats>().knockBack;
UpgradeLoc[i].GetComponent<CardStats>().pierce = Upgrade[i].GetComponent<CardStats>().pierce;
Buttonss[i].onClick.AddListener(UpgradeLoc[i].GetComponent<CardStats>().setValue);
Buttonss[i].onClick.RemoveListener((UpgradeLoc[i].GetComponent<WeaponShower>().weaponPressed));
ContinueButton.SetActive(false);
foreach (Button buttons in Buttonss)
{
buttons.onClick.AddListener(CardPressed);
buttons.onClick.AddListener(SetFalseWeaponSlots);
buttons.onClick.AddListener(CharacterStatsSetter.setCharacterStatsTexts);
}
// this sets cardtexts .
getPartsStats = Upgrade[i].GetComponent<PartsCircuitsUpgradesStats>().SetStatsTexts();
int getTexts = 2;
for (int texts = 0; texts < getPartsStats.texts.Length; texts++)
{
SetTexts(getPartsStats.texts[texts].textStats, texts);
}
// foreach(PartsCircuitsUpgradesStats.statsTexts.textDuals anan in getPartsStats.texts)
{
}
void SetTexts(string stat, int texts)
{
if (stat == null) ;
else
{
UpgradeLoc[i].transform.GetChild(getTexts).GetComponent<TMP_Text>().text = getPartsStats.texts[texts].textName;
UpgradeLoc[i].transform.GetChild(getTexts + 8).GetComponent<TMP_Text>().text = getPartsStats.texts[texts].textStats;
getTexts++;
}
}
}
}
public static void GetRandomWeapon()
{
GameObject canvas = GameObject.Find("Canvas");
SetTrueWeaponSlots();
PartsCircuitsUpgradesStats.statsTexts getPartsStats;
for (int i = 0; i < 4; i++)
{
int random = Random.Range(0, allWeaponPartsS.Count);
// Weapons[i] = AllWeapons[random];
Weapons[i] = allWeaponPartsS[random];
UpgradeLoc[i].GetComponentInChildren<TMP_Text>().text = Weapons[i].GetComponent<WeaponSyntax>().explanation;
UpgradeLoc[i].transform.GetChild(1).GetComponent<TMP_Text>().text = Weapons[i].GetComponent<WeaponSyntax>().weaponName;
Color color = UpgradeLoc[i].transform.GetChild(0).GetComponent<Image>().color;
color.a = 0f;
UpgradeLoc[i].transform.GetChild(0).GetComponent<Image>().color = color;
GameObject weaponpart= Instantiate(AllWeapons[0], UpgradeLoc[i].transform.GetChild(0).transform.position, Quaternion.identity);
// GameObject weaponpart = Instantiate(weaponsPartsFirstS, UpgradeLoc[i].transform.GetChild(0).transform.position, Quaternion.identity);
weaponParts[i] = weaponpart;
weaponpart.transform.GetChild(1).GetComponent<Image>().sprite = Weapons[i].GetComponent<SpriteRenderer>().sprite;
weaponpart.GetComponent<WeaponParts>().weaponSyntax = Weapons[i].GetComponent<WeaponSyntax>().weaponSyntax;
weaponpart.GetComponent<WeaponParts>().weaponPartType = Weapons[i].GetComponent<WeaponSyntax>().weaponPartType;
weaponpart.GetComponent<WeaponParts>().explanation= Weapons[i].GetComponent<WeaponSyntax>().explanation;
// weaponpart.GetComponent<FirstWeaponParts>().weaponSyntax = Weapons[i].GetComponent<WeaponSyntax>().weaponSyntax; // this was on you were trying implement controller support
// weaponpart.GetComponent<FirstWeaponParts>().weaponPartType = Weapons[i].GetComponent<WeaponSyntax>().weaponPartType; // this was on you were trying implement controller support
// weaponpart.GetComponent<FirstWeaponParts>().explanation= Weapons[i].GetComponent<WeaponSyntax>().explanation;
// this part sets the parts circuits and upgrades texts;
getPartsStats = Weapons[i].GetComponent<PartsCircuitsUpgradesStats>().SetStatsTexts();
int getTexts = 2;
if (getPartsStats.textThatSaysEvery_2_LevelDual.textStats != null|| getPartsStats.textThatSaysEvery_2_LevelDual.textStats != "") UpgradeLoc[i].transform.GetChild(9).GetComponent<TMP_Text>().text = getPartsStats.textThatSaysEvery_2_LevelDual.textStats;
for (int texts=0; texts < getPartsStats.texts.Length; texts++)
{
SetTexts(getPartsStats.texts[texts].textStats, texts);
}
void SetTexts(string stat,int texts)
{
if (stat == null) ;
else
{
UpgradeLoc[i].transform.GetChild(getTexts).GetComponent<TMP_Text>().text = getPartsStats.texts[texts].textName;
UpgradeLoc[i].transform.GetChild(getTexts +8).GetComponent<TMP_Text>().text = getPartsStats.texts[texts].textStats;
getTexts++;
}
}
/* UpgradeLoc[i].transform.GetChild(2).GetComponent<TMP_Text>().text = "Damage >";
UpgradeLoc[i].transform.GetChild(3).GetComponent<TMP_Text>().text = "Cool down >";
UpgradeLoc[i].transform.GetChild(4).GetComponent<TMP_Text>().text = "Bullet num >";
UpgradeLoc[i].transform.GetChild(5).GetComponent<TMP_Text>().text = "Area >";
UpgradeLoc[i].transform.GetChild(6).GetComponent<TMP_Text>().text = "Crit Chance >";
UpgradeLoc[i].transform.GetChild(7).GetComponent<TMP_Text>().text = "Crit Damage >";
UpgradeLoc[i].transform.GetChild(8).GetComponent<TMP_Text>().text = "Pierce >";
UpgradeLoc[i].transform.GetChild(9).GetComponent<TMP_Text>().text = "Knock Back >";
UpgradeLoc[i].transform.GetChild(10).GetComponent<TMP_Text>().text = Weapons[i].GetComponent<PartsCircuitsUpgradesStats>().damage.ToString();
UpgradeLoc[i].transform.GetChild(11).GetComponent<TMP_Text>().text = Weapons[i].GetComponent<PartsCircuitsUpgradesStats>().coolDown.ToString();
UpgradeLoc[i].transform.GetChild(12).GetComponent<TMP_Text>().text = Weapons[i].GetComponent<PartsCircuitsUpgradesStats>().bulletNumber.ToString();
UpgradeLoc[i].transform.GetChild(13).GetComponent<TMP_Text>().text = Weapons[i].GetComponent<PartsCircuitsUpgradesStats>().area.ToString();
UpgradeLoc[i].transform.GetChild(14).GetComponent<TMP_Text>().text = Weapons[i].GetComponent<PartsCircuitsUpgradesStats>().critChance.ToString();
UpgradeLoc[i].transform.GetChild(15).GetComponent<TMP_Text>().text = Weapons[i].GetComponent<PartsCircuitsUpgradesStats>().critDamage.ToString();
UpgradeLoc[i].transform.GetChild(16).GetComponent<TMP_Text>().text = Weapons[i].GetComponent<PartsCircuitsUpgradesStats>().pierce.ToString();
UpgradeLoc[i].transform.GetChild(17).GetComponent<TMP_Text>().text = Weapons[i].GetComponent<PartsCircuitsUpgradesStats>().knockBack.ToString();
*/
weaponpart.transform.SetParent(UpgradeLoc[i].transform.parent) ; //weaponpart.transform.parent = UpgradeLoc[i].transform.GetChild(2);
weaponpart.transform.SetAsLastSibling();
// weaponpart.GetComponent<RectTransform>().sizeDelta = UpgradeLoc[i].transform.GetChild(2).GetComponent<RectTransform>().sizeDelta;
weaponpart.GetComponent<RectTransform>().sizeDelta = new Vector2(100f,100f);
weaponpart.transform.GetChild(1).GetComponent<RectTransform>().anchorMin = new Vector2(0.06f, 0.06f);
weaponpart.transform.GetChild(1).GetComponent<RectTransform>().anchorMax = new Vector2(0.94f, 0.94f);
weaponpart.GetComponent<RectTransform>().localScale = new Vector3(1f, 1f, 0);
Buttonss[i].onClick.AddListener(UpgradeLoc[i].GetComponent<WeaponShower>().weaponPressed);
foreach (Button buttons in Buttonss)
{
buttons.onClick.RemoveListener(SetFalseWeaponSlots);
}
}
}
public static void CardPressed()
{
WeaponCharacterChoice.timescal = 1f;
UpgradeMenu.SetActive(false);
bacgroundColorS.SetActive(false);
SetCursor.SetCursorVisibilityFalse();
PauseMenu.isUpgradesTaken = true;
for (int i = 0; i < 4; i++) // this resets the upgradelocs texts;
{
for(int child=2;child < UpgradeLoc[i].transform.childCount; child++)
{
UpgradeLoc[i].transform.GetChild(child).GetComponent<TMP_Text>().text =null;
}
}
}
public static void DestroyLeftParts()
{
foreach(GameObject parts in weaponParts)
{
if(!parts.GetComponent<WeaponParts>().isPlaced) Destroy(parts);
}
}
public static void RemoveCardPressed()
{
foreach(Button buttons in Buttonss)
{
buttons.onClick.RemoveListener(CardPressed);
}
for(int i=0;i<4;i++)
{
Buttonss[i].onClick.RemoveListener(UpgradeLoc[i].GetComponent<CardStats>().setValue);
}
}
static void goldCoin() => barsetter.x += CoinExperienceSetter();
static void SetFalseWeaponSlots()
{
foreach(GameObject weaponSlots in sweaponSlots)
{
weaponSlots.SetActive(false);
}
}
static void SetTrueWeaponSlots()
{
foreach (GameObject weaponSlots in sweaponSlots)
{
weaponSlots.SetActive(true);
}
}
void SetWeaponComponentForUnlock(GameObject Core,GameObject Stock,GameObject Body)
{
weaponComponentsForUnlock weapon;
weapon.Core = Core;
weapon.Stock = Stock;
weapon.Body = Body;
}
void AddWeaponComponentForUnlock()
{
}
struct weaponComponentsForUnlock
{
public GameObject Core;
public GameObject Stock;
public GameObject Body;
}
static float CoinExperienceSetter()
{
float coinExperience = (0.2f + (0.2f * ((CharacterStats.staticExp / 100f)-1))) / ((Level) * 2);
coinExperience = 10000000000000000000f;
return coinExperience;
}
}