1
\$\begingroup\$

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.

\$\endgroup\$
  • \$\begingroup\$ By the way: OnGUI is deprecated. You should use the new UI system instead. \$\endgroup\$ – Philipp Jul 18 '17 at 9:30
2
\$\begingroup\$

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 :

Import Settings

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.

Image

Note : To create a canvas and the child image :

  1. GameObject menu > UI > Canvas
  2. Select the canvas in the Hierarchy
  3. GameObject menu > UI > Image (or right click on your canvas : UI > Image)
| improve this answer | |
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.