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 LukaKotar · Aug 10, 2012 at 07:10 PM · screenblack

How to make screen turn black?

Hi.

I would like to make the screen turn black at an event (horror tricks).

I have tried doing it with the GUI.DrawTexture() function, but I can't seem to get it to work:

 GUI.DrawTexture(new Rect(0,0,Screen.width,Screen.height), blackTexture, ScaleMode.ScaleToFit, true);

"blackTexture" is a Texture variable, that I have assigned, but no luck. Always get the same error:

NullReferenceException: Object reference not set to an instance of an object UnityEngine.GUI.DrawTexture (Rect position, UnityEngine.Texture image, ScaleMode scaleMode, Boolean alphaBlend, Single imageAspect) UnityEngine.GUI.DrawTexture (Rect position, UnityEngine.Texture image, ScaleMode scaleMode) MirrorScare+c__Iterator12.MoveNext () (at Assets/Scripts/MirrorScare.cs:20)

Comment
Add comment · Show 3
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
avatar image RodrigoSeVeN · Aug 10, 2012 at 07:16 PM 0
Share

Use only GUI.DrawTexture(new Rect(0,0,Screen.width,Screen.height), blackTexture); as you are already drawing it on the whole screen. If you still get a nullreference, than check if your variable is working. I normally use Texture2D ins$$anonymous$$d and never had any problem like this.

avatar image LukaKotar · Aug 10, 2012 at 07:18 PM 0
Share

this gives me the same error when it should happen...

avatar image RodrigoSeVeN · Aug 10, 2012 at 07:44 PM 0
Share

Please, check if your variable is working. Use 'print(blackTexture);' on 'Start()' and you will get null or the name of the texture. Besides this, there is no other element to be null on this line. Also, in your first code, you are missing one last value, the imageAspect.

1 Reply

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by Meltdown · Aug 10, 2012 at 07:47 PM

Have an inactive camera in your scene with the following settings...

 Clear Flags - Solid Color
 Background - Black
 Culling Mask - Nothing

When you need the black screen, simply disable your main camera, and enable this camera.

Comment
Add comment · Share
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

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

9 People are following this question.

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

Related Questions

URP Template Project shows black screen 2 Answers

Black layout on "play" button 1 Answer

Black screen parts after "RUN" button is pressed 0 Answers

QCAR AR no working with gui menus 0 Answers

Black screen after success build. 1 Answer


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