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 ina · May 08, 2011 at 06:33 PM · colorscreenguitextureflash

Solid color flash entire screen

What's the best way to flash a solid white (or other) color on the entire screen?

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

2 Replies

· Add your reply
  • Sort: 
avatar image
4

Answer by Peter G · May 08, 2011 at 06:50 PM

Draw a GUITexture over the entire Screen.

  1. Create a GUITexture.

  2. Create a 1x1 white square texture and apply it to the GUITexture.

  3. Change the color to whatever you want.

  4. Call the following function from a script on the flash object.


Then add this script:


function Flash (duration : float) { guiTexture.enabled = true; Invoke("Cancel", duration); }

function Cancel () { guiTexture.enabled = false; }

or, you can just put this script on a GameObject, and it will set up a GUITexture that flashes whatever color you want. It creates a GameObject. Adds a GUITexture then flashes it whenever you call Flash(). It is just encapsulating away a few variables that you have above.

private var flash : GUITexture; var flashColor : Color;

function Start () {

 var tex : Texture2D = new Texture2D ( 1 , 1 );
 tex.SetPixel( 0 , 0 , Color.white );
 tex.Apply();

 var storageGB = new GameObject("Flash");
 storageGB.transform.localScale = new Vector3(0 , 0 , 1);

 flash = storageGB.AddComponent(GUITexture);
 flash.pixelInset = new Rect(0 , 0 , Screen.width , Screen.height );
 flash.color = flashColor;
 flash.texture = tex;
 flash.enabled = false;

}

function Flash (duration : float) { flash.enabled = true; Invoke("Cancel", duration); }

function Cancel () { flash.enabled = false; }

or you can look at this example I put together that uses properties instead of doing it in Start(). Some people are against a lazy set up, so its your choice.

Comment
Add comment · Show 6 · 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
avatar image Eric5h5 · May 08, 2011 at 07:00 PM 2
Share

Just set the scale to (1, 1, 0), and leave the pixel insets at 0. Then you don't need to mess with Screen.width etc. Especially useful if the resolution happens to change.

avatar image Joshua · May 08, 2011 at 07:11 PM 0
Share

Nice answer. Could you explain what you mean with a 'lazy setup'?

avatar image Peter G · May 08, 2011 at 07:17 PM 0
Share

@Eric, a quick test on my Computer suggests that (2 , 2 , 0 ) takes up the whole screen. ( 1 , 1 , 0 ) only takes up a quarter.

avatar image Peter G · May 08, 2011 at 07:21 PM 0
Share

@Joshua Lazy loading would be waiting until an object is needed to load it. http://en.wikipedia.org/wiki/Lazy_loading $$anonymous$$y other answers both provide examples of this.

avatar image Eric5h5 · May 09, 2011 at 12:08 AM 1
Share

@Peter G: The coords and scaling are normalized, which means by definition 1.0 is full-screen. $$anonymous$$ake sure the pixel inset values are all 0, and that it's positioned at (.5, .5). I guarantee (1, 1, 0) is full-screen as I've done this a number of times.

Show more comments
avatar image
1

Answer by Rabwin · May 08, 2011 at 06:44 PM

I know you're asking for the best way, but as far as I'm aware, it's hard to know which it is. So I guess you could create a guitexture, using a 1pixel image of the colour (yeah it's dodgy but it works) and set the width and height to the resolution of the screen through script. You can then have another script enable and disable the object for a length of time. In c# it might go a little like this...

public GameObject GuiObject;

void start() { //setup the object Rect newSize = new Rect(0, 0, Screen.width, Screen.height); //Pixel Inset - Rect (x, y, width, height) GuiObject.guiTexture.pixelInset = newSize; GuiObject.SetActiveRecursively(false); }

Now you need to just use the SetActiveRecusively function to enable it, wait a while (probably using the in-build wait funciton, or Time.time) then disable the object.

This should make somewhat of a flash on screen.

Comment
Add comment · Show 2 · 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
avatar image Eric5h5 · May 08, 2011 at 06:57 PM 0
Share

Ins$$anonymous$$d of using pixel inset values, just set the scale to (1, 1). Then it always covers the entire screen regardless. Also, there's no reason to use SetActiveRecursively; that's for objects with children. Finally, there's nothing "dodgy" about using a 1 pixel image.

avatar image Rabwin · May 09, 2011 at 04:09 AM 0
Share

Alright, forgive me Eric for I'm still new to unity engine as well. At least you have now set me along the right path.

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

No one has followed this question yet.

Related Questions

Screen flashes red on damage? 4 Answers

Disco like GUITexture? 1 Answer

Red flash for each network player when he gets hit 1 Answer

Locking cursor Issue - Flash 1 Answer

Making GUITexture start transparent then fade in. 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