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

How to use part of an image for a button

Discussion in 'Scripting' started by DiogoCosta, Mar 22, 2015.

  1. DiogoCosta

    DiogoCosta

    Joined:
    Feb 15, 2015
    Posts:
    12
    I am trying to create a region select type thing with a map of a country. Below is similar to the image I will be using. I was wondering how you would create each color(region) on the map do a different function, so basically make each color its own button. The image is currently in unity as a texture.

     
  2. tobad

    tobad

    Joined:
    Mar 12, 2015
    Posts:
    90
    simple logic (but very time intensive to implement)
    create for each color area colliders and name them different.
    with onmousedown check with raycast which collider is hitted.
     
  3. blizzy

    blizzy

    Joined:
    Apr 27, 2014
    Posts:
    775
    I take it you already have a texture that is color-coded - a unique color for each area. You could make it so that when you click on the normal texture, you would map the clicked location onto your color-coded texture, then read out the pixel's color at that location.