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 Hamesh81 · Dec 20, 2014 at 01:13 PM · ifdelegateconditional

How to use conditionals with delegates?

I have one script with the following delegate below, which is fired when the URL of the website displayed in my application has been changed either by user input or due to a page redirect:

 public delegate void URLChangedDelegate (UWKWebView view, string url);

In a second script, what I would like to do is set a conditional so that I can check "if" the changed URL is a specific value and if so then load a new scene. I'm not quite sure how to do this as I have little experience with delegates. I have watched the official tutorials but they do not seem to cover this specific case. I would appreciate some advice please.

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

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

Answer by Owen-Reynolds · Dec 20, 2014 at 06:31 PM

That looks like a built-in for the uWEBkit AddOn? If so, might help to put that in the title, and I see they have a message board.

Delegates are just functions. So, you can write:

 void checkForCats(UWKWebView view, string url) {
   if(url=="catsthatlooklikehitler.com") // real page!! super cute!!
     Debug.Log("this guy's in for a real treat.);
 }

Then you hook it up as a callback however it says to. Like maybe you have to write URLchangeAction=checkForCats; (but I just made up URLchangeAction.) Then it's kind of like OnCollisionEnter. Their system just "knows" when to run it.

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 Hamesh81 · Dec 21, 2014 at 01:59 AM 0
Share

Thanks Owen, and yes my specific example was from UWeb$$anonymous$$it since that is what I'm working with at the moment. $$anonymous$$y question though was a general use case of delegates, hence why I am asking here. I think I have a better understanding of this now. So if the delegate is defined in one script and I want to call it from another script, I simply use getcomponent and then call the delegate similar to how a function is called?

Edit: Never $$anonymous$$d I've worked it out. $$anonymous$$y assumption was correct :)

avatar image Owen-Reynolds · Dec 21, 2014 at 06:51 AM 1
Share

The original word for delegate is "function pointer." The idea is you have have a variable that holds a function. Simple idea, been in use for 30+ years. But C# renamed them "delegates" just to make them more confusing (function pointer is what it is. delegate is what it does, sort of.)

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

27 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

Related Questions

|| conditional statement not working 1 Answer

Else and If 2 Answers

#if UNITY_WEBPLAYER been removed? 2 Answers

How to make a callback function 3 Answers

Code in one function call being executed on multiple frames 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