Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 ale200206distefano · Jul 07, 2020 at 05:03 PM · not workingstopfunction call

When i call a function, it doesn't run and stops the script

I'm trying to call a function in another script, but when i call it it doesn't run it at all and the script stops and exit. I got no errors. I tried debugging and it works fine till i call the function in the script, which is not executed and the script stops completely.

if(currentscene == "Level02")
{
unlock.hasUnlocked("Level02"); //this is the last line of code which the scripts executes
Invoke("Level03", 2f);
}

 public void hasUnlocked(string level)
 {
     if (level == "Level02")
     {
         Level02.enabled = true;
     }
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

Answer by ray2yar · Jul 08, 2020 at 02:31 AM

If I understood your logic.... you say IF you're in the level2.... THEN unlock level2... which loads level2.... so, wouldn't that result in continuously loading level2 ?

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 ale200206distefano · Jul 09, 2020 at 09:32 AM 0
Share

No, if i am in level 2 and i completed it, i unlock the level 2 button on the level selector scene, which is why i have unlocked.hasUnlocked("Level02"). After that is done i invoke the Level3 scene. $$anonymous$$y problem is that is stops working when it does the line unlocked.hasUnlocked("Level02").

avatar image
0

Answer by Tripleganger · Jul 09, 2020 at 10:00 AM

Could I suggest you used this to avoid any error? Please also consider that Level02.enabled will enable the Button Component in your scene, if that is what you are trying to do.

 using UnityEngine.SceneManagement;
 
 public void HasUnlocked(string level)
 {
 Scene myScene = SceneManager.GetActiveScene();
 if (myScene.name == level) Level02.enabled = true;
 }
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 ale200206distefano · Jul 09, 2020 at 11:31 AM 0
Share

Yeah i'll try it ty, but idk if this is going to solve the main issue, cause HasUnlocked is not even executed. It all stops when i call "unlock.hasUnlocked("Level02");"

avatar image Tripleganger · Jul 09, 2020 at 12:07 PM 0
Share

If hasUnlocked is not called, it means that something is wrong in this part of the script: if(currentscene == "Level02") { unlock.hasUnlocked("Level02");

 Invoke("Level03", 2f);
 }

Bear in $$anonymous$$d that if this is in Update, you are calling Invoke every frame. You might want to insert a bool that prevents this from happening. I don't know if this will fix the problem, but it might be worth trying.

avatar image ale200206distefano Tripleganger · Jul 09, 2020 at 12:26 PM 0
Share
     currentscene = Scene$$anonymous$$anager.GetActiveScene().name;
     if (currentscene == "Level01")
     {
         Invoke("Level02", 2f);
         goto Finish;
     }
     if(currentscene == "Level02")
     {
         unlock.hasUnlocked("Level02");
         Invoke("Level03", 2f);
         goto Finish;
     }
     if (currentscene == "Level03")
     {
         Invoke("Level04", 2f);
         unlock.hasUnlocked("Level03");
         goto Finish;
     }

i have smt like this. this is called when i complete the level, it's not in Update. I really don't know why this is happening

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

133 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 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

Unreliable particle behaviour when not in view 0 Answers

How to make a pause function? 3 Answers

Wheel Collider General Friction 1 Answer

Stop object collision 3 Answers

Don't destroy a variable when changing scene 2 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