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 GamesMaker · Mar 28, 2015 at 05:01 PM · unity 5uierrorjava

yield WaitForSeconds(1) ends with this error:ArgumentException: method return type is incompatible

I just started with the UI in Unity and now i created a working menu with some Buttons. Now i wanted to add a delay with WaitForSeconds(1); in my JavaScript so that if i click one of the buttons it takes a scecond until they load the new Scene. How i made my buttons: I created a canvas and added the Buttons with GameObject-->UI-->button then i created this JavaScript:

     #pragma strict
     
     function Start () {
     
     }
     
     function StartGame() {
     Application.LoadLevel(1);
      }       
     function Beenden(){
     
     Application.Quit();
     }
     
     function Anleitung() {
     Application.LoadLevel(2);
     }
     function Optionen() {
     Application.LoadLevel(3);
     }
 

I added this script to the Main Camera and added the Main Camera to the Buttons: ![alt text][1] For every button i choosed one of the functions. My problem is when i add the command WaitForSeconds(1); to one of the funtions and click the button with this function i get this Error:

 ArgumentException: method return type is incompatible
 System.Delegate.CreateDelegate (System.Type type, System.Object firstArgument, System.Reflection.MethodInfo method, Boolean throwOnBindFailure) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System/Delegate.cs:190)
 System.Delegate.CreateDelegate (System.Type type, System.Object firstArgument, System.Reflection.MethodInfo method) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System/Delegate.cs:276)
 UnityEngine.Events.InvokableCall..ctor (System.Object target, System.Reflection.MethodInfo theFunction) (at C:/buildslave/unity/build/Runtime/Export/UnityEvent.cs:99)
 UnityEngine.Events.PersistentCall.GetRuntimeCall (UnityEngine.Events.UnityEventBase theEvent) (at C:/buildslave/unity/build/Runtime/Export/UnityEvent.cs:355)
 UnityEngine.Events.PersistentCallGroup.Initialize (UnityEngine.Events.InvokableCallList invokableList, UnityEngine.Events.UnityEventBase unityEventBase) (at C:/buildslave/unity/build/Runtime/Export/UnityEvent.cs:518)
 UnityEngine.Events.UnityEventBase.RebuildPersistentCallsIfNeeded () (at C:/buildslave/unity/build/Runtime/Export/UnityEvent.cs:679)
 UnityEngine.Events.UnityEventBase.Invoke (System.Object[] parameters) (at C:/buildslave/unity/build/Runtime/Export/UnityEvent.cs:715)
 UnityEngine.Events.UnityEvent.Invoke () (at C:/buildslave/unity/build/Runtime/Export/UnityEvent_0.cs:53)
 UnityEngine.UI.Button.Press () (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/UI/Core/Button.cs:35)
 UnityEngine.UI.Button.OnPointerClick (UnityEngine.EventSystems.PointerEventData eventData) (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/UI/Core/Button.cs:44)
 UnityEngine.EventSystems.ExecuteEvents.Execute (IPointerClickHandler handler, UnityEngine.EventSystems.BaseEventData eventData) (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/EventSystem/ExecuteEvents.cs:52)
 UnityEngine.EventSystems.ExecuteEvents.Execute[IPointerClickHandler] (UnityEngine.GameObject target, UnityEngine.EventSystems.BaseEventData eventData, UnityEngine.EventSystems.EventFunction`1 functor) (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/EventSystem/ExecuteEvents.cs:269)
 UnityEngine.EventSystems.EventSystem:Update()
 


Whats the problem can someone please explain how to fix this in a easy way because im very new to Unity and Java.

unbenannt.png (3.9 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

2 Replies

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

Answer by _joe_ · Mar 28, 2015 at 05:28 PM

I advise you to use Invoke in this case, which is simpler and gets the job done:

Invoke("MyFunction", 2); //2 is the number of seconds

function MyFunction(){ Application.LoadLevel(1); }

Of course it is advisable to use Coroutines (and to switch to C# in that case) for later, more advanced control.

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 GamesMaker · Mar 29, 2015 at 12:30 PM 0
Share

Thanks that worked I had to change your command a Little bit because the command automatically started after 2 seconds but now everything works fine. Oh and in don't use C# because making Games is more like a Hobby for me mostly I only search for the things I need in the Internet try to find out how they work and then use it. Surely C# isn't that more harder to learn maybe its easier to learn but I think Java is ok for the Little games I make.

avatar image
1

Answer by maccabbe · Mar 28, 2015 at 05:08 PM

WaitForSeconds can only be used with a yield statement in coroutines.

http://docs.unity3d.com/ScriptReference/WaitForSeconds.html

Based on what you described, it is time for you to learn about coroutines

https://unity3d.com/learn/tutorials/modules/intermediate/scripting/coroutines

http://docs.unity3d.com/Manual/Coroutines.html

Comment
Add comment · Show 2 · 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 _joe_ · Mar 28, 2015 at 05:25 PM 0
Share

Using WaitForSeconds in Javascript automatically changes the function into a Coroutine

avatar image GamesMaker · Mar 29, 2015 at 12:10 PM 0
Share

Oh I mean I used the command yield WaitForSeconds I only forgot it in my Problem description but in my Script which gave me the error I used yield WaitForSeconds(1); if you mean that with "WaitForSeconds can only be used with a yield statement in coroutines." haven't read/watched the tutorials yet.

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

2 People are following this question.

avatar image avatar image

Related Questions

How can I make a new line in Unity UI text? 2 Answers

UnityEngine.UI.Graphic.OnRebuildRequested () 2 Answers

Canvas Problem 1 Answer

Failed to re-package resources even I make blank project 3 Answers

UNITY NETWORK SCOREBOARD 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