Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
1
Question by kenji255 · Sep 18, 2017 at 12:46 PM · inspectoruser interfacecalls

Place holder for various scripts/functions

So, I have just finished making dialogue boxes in my game, and for this first dialogue box, I need it to be so as soon as the dialogue box goes away (SetActive (false)), it brings up a menu, but for some reason I can't figure out how to do that. I've done lots of similar things with other menus, but the problem is thus: As there is need for this sort of thing in multiple places for different reasons, I'd like to have functionality so that when any dialogue box is SetActive (false) in the game, I have a way to call various functions from various scripts, kind of like the button UI inspector thing shown below: alt text But I can't think of how to do that! I looked into Event Triggers, but it doesn't have any events for disabling stuff... or enabling, for that matter.

At the very least, I'd like if I could just make this one box call something when I set it inactive.

Thanks, guys!

screen-shot-2017-09-18-at-63402-am.png (11.5 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
2

Answer by Hellium · Sep 18, 2017 at 01:10 PM

You will have to attach the following script to your panels so as to dispatch an event :

 [System.Serializable]
 public class SimpleEvent : UnityEvent { };

 public class MyClass : MonoBehaviour
 {
    public SimpleEvent OnGameObjectDisabled ;
 
    void OnDisable() {
        if( OnGameObjectDisabled != null )
             OnGameObjectDisabled .Invoke();
     }
 }

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 Bunny83 · Sep 18, 2017 at 01:22 PM 1
Share

Ahh damn, too slow -.-

avatar image kenji255 · Sep 18, 2017 at 10:33 PM 0
Share

Thanks!

However, kind of a noob. I added the "using UnityEngine.Events;" at the top. Now I tried to add it to my panel, and I got this: alt text How do I get around that...?

screen-shot-2017-09-18-at-43048-pm.png (33.4 kB)
avatar image Bunny83 kenji255 · Sep 18, 2017 at 11:25 PM 1
Share

The class in his example is named "$$anonymous$$yClass", not SimpleEvent. So your file should be named $$anonymous$$yClass. SimpleEvent is just a custom implementation of a UnityEvent (which actually isn't necessary when you use an event without parameters).

avatar image
1

Answer by Bunny83 · Sep 18, 2017 at 01:21 PM

You could use a component like this:

 //TriggerOnEnableChange.cs
 using UnityEngine;
 using UnityEngine.Events;
 
 public class TriggerOnEnableChange : MonoBehaviour
 {
     [System.Serializable]
     public class BoolEvent : UnityEvent<bool> { }
     public UnityEvent onEnable;
     public UnityEvent onDisable;
     public BoolEvent onToggle;
 
 
     private void OnEnable()
     {
         onEnable.Invoke();
         onToggle.Invoke(true);
     }
 
     private void OnDisable()
     {
         onDisable.Invoke();
         onToggle.Invoke(false);
     }
 }

Now you can assign a simple method to the onEnable or onDisable events. The onToggle event takes a bool parameter of the new state and is called both when the object is enabled or disabled.

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 kenji255 · Sep 18, 2017 at 10:37 PM 0
Share

Oh! I didn't look closely enough at this! I will try it right away and let you know!

Thanks!

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

71 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

Related Questions

RuntimeInspector-like or FullInspector-like UI in game-mode 0 Answers

Adding Custom Inspector to Sub Class Arrays 0 Answers

Cant drag InputField to property of script in Inspector 2 Answers

Custom Inspector, duplicates variables ? 1 Answer

Using different custom inspectorscripts 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