Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
This question was closed Feb 11, 2014 at 05:59 PM by FreeTimeDev for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by FreeTimeDev · Feb 10, 2014 at 09:15 PM · c#guibeginarea

Deleting a file inside a BeginArea and BeginHorizontal

Right now I'm trying to delete a save file.

My save files are loaded within a foreach loop and hooked to buttons. Tapping the button loads the corresponding level.

I realized I had no way to delete these levels, and so I tried to implement what I thought would be pretty easy.

 void OnGUI()
 {
     GUILayout.BeginArea(new Rect(Screen.width*.545f,(Screen.height*.25f+scrollPosition.y*-1),Screen.width*.45f,Screen.height*.7f));

     GUILayout.Label("Saved maps");
     foreach (var f in dir.GetFiles("*.dm"))
     {    
         string del = ",";
         string text = System.IO.File.ReadAllText(f.FullName);
         string[] lines = Regex.Split(text, "\n");
         string[] cells = Regex.Split(lines[lines.Length-2], del);  
         
         GUILayout.BeginHorizontal();
         if(GUILayout.Button (cells[1]+":"+cells[0]+"  "+cells[4], GUILayout.Width(Screen.width*.349f), GUILayout.Height(Screen.height*.06f)))
         {
             StartCoroutine("LoadOld");
             //Application.LoadLevel("Table");
         }
         if(GUILayout.Button ("Del", GUILayout.Width (Screen.width*.349f), GUILayout.Height(Screen.height*.06f)));
            {
             File.Delete(f.FullName);
         }

         GUILayout.EndHorizontal();
     }

     GUILayout.EndArea();
 }

The problem occurs when I add the second button (including both buttons in a Horizontal layout) and suddenly when ever the scene loads it deletes all the files without any user input. What's going wrong here?

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

  • Sort: 
avatar image
1
Best Answer

Answer by RudyTheDev · Feb 10, 2014 at 09:54 PM

You have a "`;`" after your if(GUILayout.Button ("Del", GUILayout.Width (Screen.width*.349f), GUILayout.Height(Screen.height*.06f)));, which means { File.Delete(f.FullName); } always executes.

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 FreeTimeDev · Feb 10, 2014 at 10:21 PM 0
Share

Unbelievable. I just...I'm walking away from program$$anonymous$$g the rest of the day. Thanks, I probably never would have caught that.

Follow this Question

Answers Answers and Comments

19 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

Related Questions

Multiple Cars not working 1 Answer

Drawing several BeginArea inside a BeginScrollview (GUILayout) produces an unexpected behaviour 1 Answer

Distribute terrain in zones 3 Answers

Erroe when resizing GUITextures in C# file 1 Answer

Editor Scripting Input Problem OnGUI() 1 Answer


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