Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Klickable Map segments without 3D Objekts?

Discussion in 'Scripting' started by Mr_Teels, Nov 8, 2015.

  1. Mr_Teels

    Mr_Teels

    Joined:
    Jul 14, 2015
    Posts:
    14
    Hey ...
    I work on a interaktive map. It's a supporting Programm for our local Firedepartment. Anyway ....

    I need the segments to be clickable like Buttons. But they have some realy unusual shapes (Picture).
    2015-11-08 21_41_28-Rheindelta für Plakat.psd bei 33,7% (Ebene 0 Kopie, RGB_8).png

    I tried to set a different image to a UI.Button, but the "Collision" was a rectangle.

    At first i tooked the map and Build some PolyPlanes over the Map. Every segment as a different Objekt. So i was able to work witch the MeshCollider.
    Go after the lines in Cinema4D was horrible ...

    Question:
    Is there a way to make the segments interaktabel without 3D Objekts?
    UI Tools? It would be a lot easier if i can draw them in Photoshop other something else ...




    Thank you for your Answer :)
     
  2. Cherno

    Cherno

    Joined:
    Apr 7, 2013
    Posts:
    515
    1. Get all buttons the mouse cursor is currently over (buttons might overlap).
    2. iterate through them; for each one, check if the pixel the cursor is pointing at has an alpha value of 0. If not, then break the iteration and do whatever you want with that button (call a function connected to it, or something).

    This of course requires using an alpha map for each button where the pixels that are outside the zone are transparent. Theoretically, this could also be done with a blak-white map since the map won't be rendered anyway.
     
  3. Mr_Teels

    Mr_Teels

    Joined:
    Jul 14, 2015
    Posts:
    14
    hmmm ... i will try it! thank you.
     
  4. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    8,998
  5. Mr_Teels

    Mr_Teels

    Joined:
    Jul 14, 2015
    Posts:
    14
    I found a sollution. I kann place every Segment as a picture, work like this goes a lot easier in Photoshop than Cinema4D ...
    if you ad the 2D Mesh collider to the image you can use collider detection.