Search Unity

Question How are people handling basic mouse events?

Discussion in 'Entity Component System' started by BitPax, Dec 27, 2020.

  1. BitPax

    BitPax

    Joined:
    Oct 4, 2019
    Posts:
    89
    Like how are people handling click, hover, drag, etc. for entities?
     
  2. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,761
    System that reads required inputs and writes them to a component to be used.
     
  3. BitPax

    BitPax

    Joined:
    Oct 4, 2019
    Posts:
    89
    Hey, thanks tertle for the reply! It's not clear to me what the optimal way to set this up would be. Could you show me an example?

    Say I have a 5 cubes, what's a good way to know which one I clicked using ECS?
     
  4. vectorized-runner

    vectorized-runner

    Joined:
    Jan 22, 2018
    Posts:
    398
    I use Unity.Physics CollisionWorld.CastRay to determine what's under the mouse. You can then determine if dragging, hovering etc with Input class.
     
  5. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,761
    Oh I misinterpreted what you meant. I totally forgot those mouse events were a thing tbh, I haven't used them in years.