Search Unity

ELI5 EventHandlers

Discussion in 'Scripting' started by flipwon, Oct 23, 2019.

  1. flipwon

    flipwon

    Joined:
    Dec 29, 2016
    Posts:
    179
    I'm trying to have an object simply watch another for when their OnDamaged method is called. I've tried a couple different ways but I can't seem to figure out c# eventhandlers, it seems to go right over my head.

    When object B is created, I'd like it to know when object A calls it's OnDamaged() method.
    When object A calls OnDamaged(), I'd like object B to call ExecuteMethod(), sounds easy?

    Why can't I get this?
     
  2. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,775
    Why don't you paste the non-working code you have so that we can see which part of the process you're missing? Barring that the best we could do is post a link to some tutorial (or just write one in a comment), which doesn't sound like what you need. It sounds like you've got most of the ideas of the process and need to figure out the syntax.
     
  3. flipwon

    flipwon

    Joined:
    Dec 29, 2016
    Posts:
    179
    Actually, I just figured it out now. My issue was with the method signature not matching the EventHandlers

    I think I got the hang of this now :)