Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by djremiks · Sep 20, 2016 at 09:29 AM · loop

For loop work well except on third state

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) alt text 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();
     }
 }
 


capture-decran-2016-09-20-a-120159.png (68.3 kB)
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by DiegoSLTS · Sep 20, 2016 at 09:07 PM

I don't understand what those 3 and 6 states mean, but for the framerate drop try to remove those print calls in the update and anything that prints to the console. It has a big impact in performance if you're printing several times on every frame.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image djremiks · Sep 21, 2016 at 09:02 AM 0
Share

In fact the problem os "states" was occured a the third time the button was pressed. thank you for the tips of print i have too much print/frame. Finally I solved the problem putting the setSizeBarre (); partially on update() (only the size change)

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

70 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How do i make Unity seamlessly loop my background music? 5 Answers

How do I get an animation to loop back from a certain point? 1 Answer

How should I prep audio assets for looping so as to avoid pops clicks etc. 0 Answers

Trigger a certain number of loop in animation on button down 0 Answers

How to make object fall loop? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges