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 /
avatar image
0
Question by Orggrim · Mar 16, 2013 at 06:22 AM · c#programmingmethod

Question about C# and using Methods...

Hi, I am currently trying to create a game that runs a basic thermostat

I have a basic function that that when a GUI button is clicked, it checks the if statement, if thats true, then decreases the ambient temperature by 1 every three seconds

Here is the code of the function...


 int Choice;
     
     IEnumerator AC()
     {
      int DesiredInt = 65;
      int AmbientInt = 78;    
         
      int Choice = 0;
         if (Choice == 0)
             {    
                 if (AmbientInt > DesiredInt)
                 {
                 yield return new WaitForSeconds(3);
                 AmbientInt -= 1;
                 }
             }
     
     }


Here is the code I am trying to use to when I click the GUI button, it runs this function


 if (GUI.Button(ACRectPercent,"A/C On"))
         {
     
             AC()
             {   // <--- LINE 75 HERE!
                 
             }
                         
         }


I keep getting an error for the top brace under "AC" that says

"Assets/Scripts/ACon.cs(75,25): error CS1525: Unexpected symbol `{'"


Ive never written anything in C# for Unity, so its been kind of a learning process. Any help as to why I am getting this error would be greatly appreciated, or any pointer on how to screw up less would also be appreciated

Please let me know if you need any extra info!

Comment
Add comment · Show 1
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 Benproductions1 · Mar 16, 2013 at 06:30 AM 0
Share

you don't need the {}

2 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by paulaceccon · Mar 16, 2013 at 10:03 AM

To call a co-routine, you have to use StartCoroutine(AC());

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 Orggrim · Mar 17, 2013 at 01:18 AM 0
Share

You just cleared up the last of my issues! Thank you very much!!!!

avatar image
1

Answer by Khada · Mar 16, 2013 at 06:32 AM

In short it should be 'AC();'. If you give it braces, it thinks you are trying to define a method (or redefine in this case). Also, I don't think you can yield within the OnGUI method but I'm not sure.

Comment
Add comment · Show 3 · 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 Orggrim · Mar 16, 2013 at 07:19 AM 0
Share

Well I got the error to go away, but I get no activity when I click the button now =( Thxs though for your help!

avatar image Khada · Mar 16, 2013 at 07:36 AM 0
Share

I'm glad the error's gone. Like I said, I don't think yielding from the OnGUI method will give you any results or the results you want/expect. Better to just use a few floats with Time.deltaTime in the Update method.

Also, can you please mark the question as answered (gray tick icon)? It helps keep the site clean and gives credit to the volunteers who help :)

avatar image Orggrim · Mar 16, 2013 at 07:38 AM 0
Share

Well its not even the yield, I threw a debug.log at the very beginning of the function just to see if it was even reading it and got nothing, would the yield stop the function from even being called?

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

13 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

Related Questions

Multiple Cars not working 1 Answer

Instantiating Prefabs through Editor Script 1 Answer

Problem with getting a value from a enum 2 Answers

Best way to limit the functionality of Lua scripting? 1 Answer

Distribute terrain in zones 3 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