Hello
I am not a developper but i am doing my best and sorry for my "google helped English ! =)
Thank you for your help , this problem is inexplainable for me !
I have a button that increases the size of the gauge but the “for” loop does not work only on the 3rd state. (I focus only on the widht of jauge problem) The loop has 6 states
If I execute the function in question " update () " it works but it drops the frame per second . The function Concerned by the problem is: setSizeBarre ();
please help me undestand the problem, I think it is a order of execution problem or a runtime problem but I dont know…
here is a picture (the jauge is incremented in width)
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class jauge : MonoBehaviour
{
public static int jaugeCase;
public string typeEvol;
enum listTypeEvol { Engine, Armor, Weapon };
listTypeEvol listTypeEvols;
private GameObject laBarre;
private bool limit = true;
private int limitint;
private int priceEvol;
private GameObject priceEvolTxt;
public globals globals;
public void calculatePrice()
{
switch (typeEvol)
{
case ("Engine"):
priceEvolTxt = GameObject.FindGameObjectWithTag("textEngine").gameObject;
priceEvolTxt.name = "Tester";
priceEvolTxt.GetComponent<Text>().text = priceEvol.ToString();
limitint = PlayerPrefs.GetInt("_saveEngine");
break;
case ("Weapon"):
priceEvolTxt = GameObject.FindGameObjectWithTag("textWeapon").gameObject;
priceEvolTxt.name = "TesterWeapon";
priceEvolTxt.GetComponent<Text>().text = priceEvol.ToString();
limitint = PlayerPrefs.GetInt("_saveWeapon");
break;
case ("Armor"):
limitint = PlayerPrefs.GetInt("_saveArmor");
break;
default:
print("par defautl");
break;
}
switch (limitint)
{
case 0:
priceEvol = 25;
print("prix de leveol " + priceEvol);
break;
case 1:
priceEvol = 25;
print("prix de leveol " + priceEvol);
break;
case 2:
priceEvol = 50;
print("prix de leveol " + priceEvol);
break;
case 3:
priceEvol = 75;
print("prix de leveol " + priceEvol);
break;
case 4:
priceEvol = 100;
print("prix de leveol " + priceEvol);
break;
case 5:
priceEvol = 150;
print("prix de leveol " + priceEvol);
break;
case 6:
priceEvol = 200;
print("prix de leveol " + priceEvol);
break;
default:
print("par defautl");
break;
}
}
public void testenum()
{
while (limit)
{
limitint++;
laBarre = this.gameObject;
laBarre.transform.GetChild(1).name = "nouveua";
calculatePrice();
if (globals.gems >= priceEvol)
{
laBarre.transform.GetChild(0).GetComponent<RectTransform>().sizeDelta += new Vector2(37.5f, 0);
updateShip();
return;
}
else {
print("Pas assez d'argent");
return;
}
}
return;
}
public void updateShip()
{
int tempLevel;
switch (typeEvol)
{
case "Engine":
print("Engine upgraded !");
tempLevel = PlayerPrefs.GetInt("_saveEngine");
print(PlayerPrefs.GetInt("_saveEngine"));
if (tempLevel == 6 || limitint == 6)
{
limit = false;
print("Deja fini d'upgrader");
return;
}
else if (tempLevel < 6)
{
tempLevel++;
setSizeBarre();
globals.refreshData(arrstring: "_saveEngine", arr: tempLevel);
print(PlayerPrefs.GetInt("_saveEngine"));
}
break;
case "Weapon":
print("Engine upgraded !");
tempLevel = PlayerPrefs.GetInt("_saveWeapon");
print(PlayerPrefs.GetInt("_saveWeapon"));
if (tempLevel == 6 || limitint == 6)
{
limit = false;
print("Deja fini d'upgrader");
return;
}
else if (tempLevel < 6)
{
tempLevel++;
setSizeBarre();
globals.refreshData(arrstring: "_saveWeapon", arr: tempLevel);
print(PlayerPrefs.GetInt("_saveWeapon"));
}
break;
default:
print("Rien de caucher");
break;
}
return;
}
void Update()
{
****//IF I DO THIS IT IS WORK FINE BUT THE FPS FALL TO 10FPS :/
// setSizeBarre();****
}
void Start()
{
setSizeBarre();
}
void setSizeBarre()
{
switch (typeEvol)
{
case ("Engine"):
print(limitint + "est mon niveau pour engine");
laBarre = this.gameObject;
limitint = PlayerPrefs.GetInt("_saveEngine");
break;
case ("Weapon"):
laBarre = this.gameObject;
limitint = PlayerPrefs.GetInt("_saveWeapon");
break;
case ("Armor"):
laBarre = this.gameObject;
limitint = PlayerPrefs.GetInt("_saveArmor");
break;
default:
print("par defautl");
break;
}
for (int i =0; i < limitint; i++)
{
print ( limitint + "est la limite de la boucle");
laBarre.transform.GetChild(0).GetComponent<RectTransform>().sizeDelta = new Vector2(37.5f * limitint, 75.2f) ;
}
}
void OnGUI()
{
calculatePrice();
if (limitint == 6)
{
limit = false;
}
}
public void resetData()
{
PlayerPrefs.DeleteAll();
}
}