Added: 1 year ago
From: prime31studios
Views: 8,449
Sort by time | Sort by thread (beta)

Link to this comment:

Share to:

All Comments (33)

Sign In or Sign Up now to post a comment!
  • Whilst I find the plug-ins from Prime31 great, the attitude and C# snobbery is pure amateur.

    Sorry, but I've now spoken to a few very very experienced game technicians (i.e. they're not just programmers, they build engines, tools etc), and they've taken a look at Unity and Javascript (mono), and said that C# is not superior in any way, and in fact, said Javascript actually made more sense for unity.

    So get off your high horse Prime31

  • @juicymangoze Many thanks for including your opinion just as we did in the video. We are making tutorial videos and thus would like those watching to be using the best tool. The advantages of C# over JS are concrete and there are many of them but that is a discussion too large for here. Some advantages are:

    - TONS of C# learning/documentation resources

    - language features that are not available in JS

    - no sneaky compiled code (look at compiled output of JS transform.position.x = 3 as an example)

  • This is a wonderful tutorial!  I went from a modest understanding of listeners and subscriptions to feeling ready to begin using them in complex applications in just 11 minutes. I found it especially helpful that you took time to explain each line and its role using both proper terminology and newbie-friendly explanations. Thanks a bunch!

  • @johnny3734 I used to think the same thing. (I started out with unityscript for unity) but what it comes down to is.. there aren't any resources available for unityscript (unity does not use pure javascript!) and there are myriads of resources available for c#. If you're smart, you'll drop unityscript and use c# asap. You'll thank me later.

  • There's nothing wrong with JavaScript, I think it's the funnest to code out of any.

  • Thanks for this tutorial - I've been hacking around in Unity for a while but have decided to grow up a bit and learn to do some things correctly. Enjoyed the first tutorial - looking forward to following along with the rest :-)

  • to get around having to check for null everytime you fire an event you can give it a single empty delegate so you technically never have zero listeners.

    eg

    static event DelegateThing OnThingEvent = delegate {};

    It's messy but it works well :)

  • You forgot to mention C# is 20 times faster than java script.

  • @chemicalvamp actually it isn't - once your C#, JS or Boo scripts are compiled they all run the same - Unity would never have used it otherwise.

  • Top stuff!

  • Top stuff!

  • Hi Again, I started to use them in my code and I got it to work for me. Initially I thought I could trigger the event from anywhere so I had problems; "events can only be invoked from within the class that declared them" (msdn)... just as you did in your video with the GUi.Button. (msdn does talk about protected invoking method to allow derived classes to invoke events, but for me is baby steps now :)).

  • So what I am doing for now is having a - public static bool varName - that I can set to true or false from anywhere/any script, then if this static var is true my event is set to true (triggered) in the class that declared the event.

    Is this ok, or maybe I am overusing static variables and it would be better/safer to trigger events in a different way? Really happy about this video tutorial, I started using events/delegates only after watching this. Thanks

  • @HokutoTC A common method is to put events in a seperate postoffice style class. Each event then has a method to invoke it. So this solves the 'must be called from the same class' problem PLUS allows you to intercept event calls and do sanity checks and debugging easier. In fact ReSharper for visual studio will write the invoker function for you (maybe plain VS does too).

    The other way around it is to NOT use events, just delegates alone which don't have those restrictions, but it's more risky

  • This seems similar to "CSharpMessenger Extended" (google it). Other than performance is there any reason it's better? I notice for one thing you will get AutoComplete for the event name, instead of having to type a string.

  • @St4rdog its similar but the key difference is that native events are associated with an object whereas the Messenger Extended is a string based publisher/subscriber system.  Events will be faster due to skipping the initial string match.

  • Great tutorial, practical and to the point. Thanks!

    I found some generic information about this topic online but your example did it for me, will be using events/delegates from today :) - please do more :) c#/Unity :)

    QUESTION: In term of performance on iOS, are events/delegates (with maybe quite a few events and listeners in a scene...) good to use or is there some performance issue compared to use some other solution to do the same things?

  • @HokutoTC performance will be excellent on mobile. Events are WAY faster than SendMessage and will beat out any alternatives (like subscriber/message solutions).

  • Thanks for your effort prime31studios, I'm a developer switching from AS3 to C# and this was exactly what I was looking for. So happy you made this :)

  • any tips for learning from scratch, i cant seem to find a good tutorial for someone who doesnt know how any of it works

  • @lucidskater there is an absolutely vast amount of C# tutorials for beginners on the web. That is one of the major reasons I always suggest C# over UnityScript. If you search the web for UnityScript tutorials you find next to nothing because it only exists in Unity. C# on the other hand has literally thousands of books and countless tutorials available.

  • @lucidskater a quick web search will get you literally thousands of C# tutorials for beginners. There are also tons of books as well.

  • @lucidskater and you won't.

  • Wow - thanks! I went and created some adhoc event system using C# reflection, but I wish I'd found this first. Oh well - at least it was a learning experience.

  • @Prime Thank you so much for this video. I have been looking for ways to help me to improve my c# skills and this fits the bill!

    I was thinking a good way to apply this was to have a "game manager" listen to player events (health, ammo, state), then have the manager broadcast the events to the UI objects like updating the health bar.

    Would this be an appropriate way to utilize events and delegates?

  • @evilrobotmechanic that sounds like a good use. Messengers could be a good topic for another tutorial video also...hmmm...

  • Oh, where were you before last September when I taught myself about events?! :-O Good stuff; events have changed my Unity coding life so much for the better, and this is a great intro to them. A couple questions, though, on convention. You used camelCase for onPoweredUp. I've used PascalCase for my events. Have you found a standard on this? The references I've found seem to use PascalCase. And what about the use of the prefix "On"? Got any info on standards for its usage? Thanks!

  • Thanks a lot! Very, very useful!

  • such a useful tut, thanks Prime31, cant wait to see more!

  • Great video! What would be the benefit/difference of using events instead of a Messenger system?

  • @jjonasz a messenger system is very similar. The difference here is mainly that you are listening to a specific event on a specific object and getting under the covers native Mono performance. A quick example based on the bouncing boxes in the tutorial: you could have a split screen game with 2 players playing at the same time. When player 2 gets a power up, you only want the boxes on player 2's screen to bounce so you could have a manager object for each player posting the events.

  • one word: AWESOME

  • AMAZING! I love you prime :)

Loading...
Alert icon
0 / 00Unsaved Playlist Return to active list
    1. Your queue is empty. Add videos to your queue using this button:
      or sign in to load a different list.
    Loading...Loading...Saving...
    • Clear all videos from this list
    • Learn more