Search Unity

Question Using OnDetected event from SensorToolkit by Micosmo

Discussion in 'Editor & General Support' started by LeFuji, Oct 16, 2020.

  1. LeFuji

    LeFuji

    Joined:
    Oct 2, 2018
    Posts:
    18
    Hello everyone!

    I hate opening any kind of post like this, but I am truly lost.

    I'm using the Sensor Toolkit from Miscosmo (https://micosmo.com/sensortoolkit/#home) and one of the main features I need to use is to save the object encountered as soon as he detects it, in order to fire bullets towards its enemy.

    Thing is I'm not that expert in programming (But I do know all the basics you could hope for), and I'm really lost on the EventHandler part (Events in general, actually).

    I'm reading a lot of information regarding events, but it is still so blurry to me.

    That's what I hate to ask: Do anyone spare some time, to point to a specific tutorial about event handlers, specially if anyone is used to running the Sensor Toolkit mentioned? I kinda need to mix the event usage with the tools provided with the sensor toolkit.

    I hope that answers like "Google it" won't be something here, I'm doing this since yesterday. The tutorials that made any sense for me were ithcyowls at https://itchyowl.com/events-in-unity/, which has excelent coverage on what is an event, how it help build better games, but I can't understand how to use this with the toolkit.

    Thanks for any help that might open my eyes!
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,745
    I don't have specific experience with that API, but let me offer you some tips:

    Generally this is done by keeping a local reference to the thing you want to keep around.

    You would need a mechanism to find what its enemy is, and then you can use something like transform.LookAt() to turn to face it on the +Z direction.

    Often a good way to get a working knowledge of a complex system like Unity is to try a few simple tutorials and get a feel for what goes where. There are tons of beginner tutorials and every one of them contains nuggets that will serve you well in trying to get this to work, including how to use events generally, and how to use events specifically in the Unity context. From that it should soon be apparently how the above API uses them.

    But I highly recommend starting with some just-Unity stuff before you try introducing third-party APIs. Regardless of how much coding experience you have, you need to feel at home with how Unity organizes stuff. Unity uses a component model for the most part, and once you grasp how Components are slotted into GameObjects, and Assets are slotted into Components, and how scripts are just special instances of Components, you'll be able to reason about your own problem space better.
     
  3. LeFuji

    LeFuji

    Joined:
    Oct 2, 2018
    Posts:
    18
    That does makes a lot of sense! Haha

    Yeah, thinking it through now, nothing that I'm familiarized with now came while working on something more complex, rather doing some small and "pointless" project, just for the sake of it.

    I will get a couple of tutorials and follow it, while taking some creativity into trying small changes for netter understanding...

    Thanks man. :)