Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by LRG · Nov 11, 2013 at 08:42 PM · effecttintdarken

GUI.DrawTexture weird behaviour

Sorry for the relatively long question.

I am trying to use GUI.DrawTexture to darken the screen with a specific color. To darken the screen, apparently the recommended way is to change the GUI.color. This is what I am doing.

However, I also wanted to tint it blue, so I am also loading a single-pixel texture and tinting it dynamically:

 mTexture = Resources.Load("textures/blackPixel") as Texture2D;

 // Make the texture pixels blue.
 mTexture.SetPixel(0, 0, effectColor);
 mTexture.SetPixel(0, 1, effectColor);
 mTexture.SetPixel(1, 0, effectColor);
 mTexture.SetPixel(1, 1, effectColor);
 mTexture.Apply(false);

Once I have that texture created, I am drawing a texture overlay using that texture and modifying the alpha:

 var savedColor = GUI.color;
 mColor.a = 0.3f;
 GUI.color = mColor;
 GUI.DrawTexture(new Rect(0, 0, Screen.width, Screen.height), mTexture);
 GUI.color = savedColor;

However, the result is the following:

  • If I do all of this in a new script component (called ScreenEffect) and I dynamically instance this script from within another script, then it works as expected (The screen is darkened and tinted blue).

  • If I attach the script in the editor (which should be just the same, I use all defaults), then the screen is darkened but the screen is not tinted blue at all.

Sub-Question 1: Is my approach right? Or is there an easier way? Just doing a GUI.color = Color.blue doesn't seem to work at all (which is why I am doing the weird texture-creation thing).

Sub-Question 2: Why would it work as expected when I instance it dynamically, but not work when I add the script through the editor? Any idea?

Thanks and sorry for the lengthy question.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

16 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Audio Low Pass Filter Not Working 1 Answer

In what way would be best to achieve a retro Gameboy simulation 0 Answers

How can I do such as that effect for my water sprite in Unity? 1 Answer

How to make Sword Trail Effect 1 Answer

Change color of Crease Image Effect 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges