Search Unity

How to break FOR if "i" has been reached the found inventory items?

Discussion in 'Scripting' started by Slyrfecso1, Oct 15, 2015.

  1. Slyrfecso1

    Slyrfecso1

    Joined:
    Jul 16, 2012
    Posts:
    100
    SOLVED:)

    Code (CSharp):
    1.  
    2.  
    3. private ItemDatabase database;
    4.  
    5. //ÖSSZEÁLLÍTÁS VÉGÖSSZEGE
    6.             GUI.Label(new Rect(Screen.width / 2 - 170, 360, 60, 25), "Az összeállítás termékei:" , szovegbold);
    7.          
    8.             database = GameObject.FindGameObjectWithTag("Item Database").GetComponent<ItemDatabase>();
    9.          
    10.             string nevek = "";
    11.             string arak = "";
    12.             int total = 0;
    13.             string vegosszeg = "";
    14.  
    15.  
    16.             if (GameObject.FindGameObjectsWithTag("Player") != null)
    17.             {
    18.                 GameObject[] objectsPrice = GameObject.FindGameObjectsWithTag("Player");
    19.                 foreach (GameObject go in objectsPrice)
    20.                 {
    21.                     if (go.name != null)
    22.                     {
    23.                         for (int i = 0; i < 552; i++)
    24.                         {
    25.                             if (go.name == database.items[i].itemName)
    26.                             {
    27.                                 int price = int.Parse(database.items[i].itemPrice);
    28.                                 arak +=database.items[i].itemPrice + " Ft+Áfa" + "\n";
    29.                                 nevek +=database.items[i].itemName + "\n";
    30.                                 total += price;
    31.                             }
    32.                         }
    33.                     }
    34.                 }
    35.             }
    36.          
    37.          
    38.          
    39.             GUI.Label(new Rect(Screen.width / 2 - 170, 380, 60, 25), nevek, szoveg);
    40.             GUI.Label(new Rect(Screen.width / 2 + 40, 380, 60, 25), arak, szovegjobbraZART);
    41.             GUI.Label(new Rect(Screen.width / 2 + 40, 360, 60, 25), "Nettó ár:" , szovegjobbraZART);
    42.          
    43.             GUI.Label(new Rect(Screen.width / 2 - 170, 525, 60, 25), "Az összeállítás:" , szoveg);
    44.             GUI.Label(new Rect(Screen.width / 2 - 170, 495, 60, 25), "Az összeállítás végösszege:" , szoveg);
    45.          
    46.             vegosszeg = total.ToString();
    47.          
    48.             GUI.Label(new Rect(Screen.width / 2 +40, 495, 60, 25), vegosszeg + " Ft+Áfa" , szovegjobbraZART);
    49.             if(GUI.Button(new Rect(Screen.width / 2 - 40, 522, 140, 20), "MEGRENDELÉSE"))
    50.              
    51.             {
    52.              
    53.             }
     
    Last edited: Oct 18, 2015
  2. JamesLeeNZ

    JamesLeeNZ

    Joined:
    Nov 15, 2011
    Posts:
    5,616
    break;
     
    Kiwasi likes this.
  3. Suddoha

    Suddoha

    Joined:
    Nov 9, 2013
    Posts:
    2,824
    May the force be with you if you run that code in OnGUI ...:confused:
     
    Kiwasi likes this.
  4. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    Can you please learn to use code tag properly?

    http://forum.unity3d.com/threads/using-code-tags-properly.143875/
     
  5. Slyrfecso1

    Slyrfecso1

    Joined:
    Jul 16, 2012
    Posts:
    100
    Hi,

    I have changed my first post, and this is full working.
     
  6. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    This really applies for any use of OnGUI. ;)

    But this is a particularly bad one.

    To the OP: Why not cache a couple of those references? Using GameObject.Find multiple times every frame is asking to be killed on performance. You should also check out the new UI tools. A massive improvement in performance and appearance and usability from OnGUI
     
    Suddoha likes this.