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. Dismiss Notice

DrawGUITexture in script?

Discussion in 'Scripting' started by Rutenis, Nov 21, 2014.

  1. Rutenis

    Rutenis

    Joined:
    Aug 7, 2013
    Posts:
    297
    Hey guys, is it possible to draw a gui texture in script? Any ideas?

    -Thanks! :)
     
  2. Ruekaka

    Ruekaka

    Joined:
    Sep 12, 2014
    Posts:
    119
  3. Rutenis

    Rutenis

    Joined:
    Aug 7, 2013
    Posts:
    297
  4. SeriousBusinessFace

    SeriousBusinessFace

    Joined:
    May 10, 2014
    Posts:
    127
  5. Rutenis

    Rutenis

    Joined:
    Aug 7, 2013
    Posts:
    297
    Meh, ended up working with DrawTexture. It would have been easy to do this with mousePosition, but in this case i needed touch, so thats why i wanted GuiTexture, so i could use HitTest. But with DrawTexture i couldnt.

    Thanks for the help tho guys.

    In case you would like to see the code:

    Code (csharp):
    1. GUI.DrawTexture(slotRect, slots[i].itemIcon);
    2.  
    3.  
    4. foreach (Touch touch in Input.touches)
    5.                     {
    6.                         Vector3 inputGuiPosition = touch.position;
    7.                         inputGuiPosition.y = Screen.height - inputGuiPosition.y;
    8.  
    9.                         if(Input.touchCount > 0)
    10.                         {
    11.                             if(slotRect.Contains(inputGuiPosition))
    12.                             {
    13.                                 ItemRec(slots[i]);
    14.                                 //Debug.Log(currentItemId);
    15.                                 if(currentItemId == 2)
    16.                                 {
    17.                                     Debug.Log("Touched Ms");
    18.                                 }
    19.  
    20.                                 if(currentItemId == 3)
    21.                                 {
    22.                                    Debug.Log("Touched Mn");
    23.                                 }
    24.                             }
    25.                         }
    26.                     }