I'm using OnGUI to draw a rect when I "box select" or "drag select". The texture that gets drawn is a PNG file made in Paint.Net with the opacity - alpha channel set quite low. In Unity however, when I go to box select, the texture is completely opaque. How do I get Unity to honor the alpha set in Paint.Net? I also wouldn't mind using Unity itself to adjust the opacity, but I haven't found such an option in the import texture part of the inspector.
First of all, avoid at all costs OnGUI except for debug purpose. Use the Unity GUI system.
In your favorite image software (Paint.Net), set the opacity of your image to 1 and import your image into Unity. Now, take a closer look to the following screenshot representing the Import Settings of an image and do the same to your own image :
The main things to notice are :
- Texture type : Sprite (2D and UI)
- Alpha source : Input Texture Alpha
- Alpha is Transparency : checked
Then, in your scene, add a new
Canvas and add an
Image as a child. Select the
Image gameobject and set your image as a sprite of your image. Finally, you will be able to manage the opacity using the
Alpha channel of the sprite color.
Note : To create a canvas and the child image :
- GameObject menu > UI > Canvas
- Select the canvas in the Hierarchy
- GameObject menu > UI > Image (or right click on your canvas : UI > Image)