title: How to Get Coordinates from Hex Map on Click in Unity
body: <p>I'm making the board game known as Hex.  When I click on a tile, it changes to either blue or yellow, but I need to also be able to know what the coordinates of that tile are.</p>
  
  <p>I can't use...</p>
  
  <pre><code>rend.transform.position;
  </code></pre>
  
  <p>...because the the coordinates I want to receive look similar to this (0,0) being the bottom left and (0,1) above it:
  <a href="https://i.stack.imgur.com/Q1Yle.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Q1Yle.png" alt="enter image description here"></a> </p>
  
  <p>The coordinates in the console are the one's I need to receive.</p>
  
  <p><a href="https://i.stack.imgur.com/n6nHf.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/n6nHf.png" alt="enter image description here"></a></p>
  
  <p>I printed those out by using the column and row variables when I generated the hex map:</p>
  
  <pre><code>using System.Collections;
  using System.Collections.Generic;
  using UnityEngine;
  using UnityEngine.UI;
  
  public class HexMap : MonoBehaviour
  {
   // Use this for initialization
   void Start()
   {
      GenerateMap();
   }
  
  public GameObject HexPrefab;
  
  public void GenerateMap()
  {
      for (int column = 0; column &lt; 11; column++)
      {
          for (int row = 0; row &lt; 11; row++)
          {
              // Instantiate a Hex
              Hex h = new Hex(column, row);
  
              Instantiate(HexPrefab, h.Position(), Quaternion.identity, this.transform);
  
              Debug.Log(column + "," + row);
          }
      }
  }
  }
  </code></pre>
  
  <p>I want to be able to get the coordinates when I click a hex tile using this script here:</p>
  
  <pre><code>using System.Collections;
  using System.Collections.Generic;
  using System.IO;
  using System.Net;
  using UnityEngine;
  using UnityEngine.Networking;
  
  public class ColorChange : MonoBehaviour {
  
  public Color[]colors; // allows input of material colors in a set sized array
  public SpriteRenderer rend;  // what are we rendering? the hex
  
  public enum Player {ONE, TWO};
  public static Player currentPlayer = Player.ONE;
  
  // Use this for initialization
  void Start () {
      rend = GetComponent&lt;SpriteRenderer&gt; (); // gives functionality for the renderer
  }
  
  void NextPlayer() {
  
     if( currentPlayer == Player.ONE ) {
        currentPlayer = Player.TWO;
     }
     else if( currentPlayer == Player.TWO) {
        currentPlayer = Player.ONE;
     }
  }
  
  // Update is called once per frame
  void OnMouseDown () {
      // if there are no colors present nothing happens
      if (colors.Length == 0)
          return;
  
      if (currentPlayer == Player.ONE)
          rend.color = colors [0];
      else if (currentPlayer == Player.TWO)
          rend.color = colors [1];
  
      NextPlayer();
  }
  </code></pre>
  
  <p>Here is the script I use to determine where the hex tiles need to be:</p>
  
  <pre><code>using System.Collections;
  using System.Collections.Generic;
  using UnityEngine;
  
  public class Hex{
  
  public Hex (int q, int r){
      this.Q = q;
      this.R = r;
  }
  
  public readonly int Q; // x
  public readonly int R;  // y
  
  static readonly float WIDTH_MULTIPLIER = Mathf.Sqrt(3) / 2;
  
  public Vector2 Position(){
      float radius = 0.513f;
      float height = radius * 2;
      float width = WIDTH_MULTIPLIER * height;
  
      float vert = height * 0.75f;
      float horiz = width;
  
      return new Vector2(horiz * (this.Q - this.R/2f), vert * this.R);
  }
  }
  </code></pre>
  
  <p>I was thinking I need to be able to assign each Hex Model the value of column and row when it is instantiated, but I'm not sure how to do that.  I tried several solutions I found online as well as using GetComponent, but I wasn't able to make them work.
  If anyone has an idea on how this might be possible I would greatly appreciate it!</p>