Search Unity

Graphics.DrawTexture: problem with color argument

Discussion in 'Immediate Mode GUI (IMGUI)' started by angel_m, Mar 27, 2016.

  1. angel_m

    angel_m

    Joined:
    Nov 4, 2005
    Posts:
    1,160
    Hi, I 'm trying to use this code:

    var mytexture : Texture;
    var greencolor : Color = Color(0,1,0,1);

    function OnGUI(){

    Graphics.DrawTexture(Rect(100,100,48,48),mytexture, greencolor);

    }


    And I receive this error in the console:

    Assets/CrossGUI.js(54,21): BCE0023: No appropriate version of 'UnityEngine.Graphics.DrawTexture' for the argument list '(UnityEngine.Rect, UnityEngine.Texture, UnityEngine.Color)' was found.

    Any idea?
     
  2. McMayhem

    McMayhem

    Joined:
    Aug 24, 2011
    Posts:
    443
    There is only one override of Graphics.DrawTexture that accepts a color parameter:
    Code (CSharp):
    1. public static void DrawTexture(Rect screenRect, Texture texture, Rect sourceRect, int leftBorder, int rightBorder, int topBorder, int bottomBorder, Color color, Material mat = null);
    So if you want to specify the color, you're going to have to fill in the rest of that info. The good thing is that most of that stuff can be set to default values:
    Code (CSharp):
    1. Graphics.DrawTexture(Rect(100,100,48,48), mytexture, new Rect(0, 0, mytexture.width, mytexture.height), 0, 0, 0, 0, greencolor, null);
    2. //You can actually skip the material parameter since it defaults to "null"
    Hope that helps some. Let me know if you need more clarified.
     
  3. angel_m

    angel_m

    Joined:
    Nov 4, 2005
    Posts:
    1,160
    Thanks,for the response.
     
  4. Taobao

    Taobao

    Joined:
    Oct 25, 2015
    Posts:
    9
    You probably want to use new Rect(0f, 0f, 1f, 1f) instead of new Rect(0, 0, mytexture.width, mytexture.height)