Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
1
Question by Story Specialist · May 07, 2010 at 10:27 AM · javascriptguifade

How can I individually fade the background (and not the GUI)?

Hey all,

I'm trying to make a script that will allow me to fade the background. I've managed to find and edit one, namely this:

public var fadeOutTexture : Texture2D; public var fadeSpeed : float = 0.3; var drawDepth : int = -1000; private var alpha = 1.0; private var fadeDir : int = -1; private var screenwidth = Screen.width; private var screenheight = Screen.height;

function OnGUI(){

 alpha += fadeDir * fadeSpeed * Time.deltaTime; 
 alpha = Mathf.Clamp01(alpha);   

 GUI.color.a = alpha;

 GUI.depth = drawDepth;

 GUI.DrawTexture(Rect(0, 0, screenwidth, screenheight), fadeOutTexture);

}

function fadeIn(){ fadeDir = -1;
Debug.Log ("ScreenFade : Fading In"); }

function fadeOutIn(waitTime : float){ fadeOut(); Debug.Log ("ScreenFade : Fading Out and In"); yield WaitForSeconds (waitTime); fadeIn(); }

function fadeOut(){ fadeDir = 1;
Debug.Log ("ScreenFade : FadingOut"); }

function Start(){ alpha=1; fadeIn(); }

It works very well, but what I would like to is fade everything out, except for the GUI. I've tried managing this with GUI.Depth, but I read somewhere on the forum that the GUI is always on top, no matter what.

I'm drawing a background with DrawTexture (which I change dynamically throughout the game), so it's part of the GUI, and that means it either all fades, or nothing does.

Is there a way for me to assign a lower/higher depth to the individual DrawTexture, so I can isolate it (read: fade only that DrawTexture)? I guess what I need, is for this fade texture to get above the DrawTexture, but under the other GUI elements.

Thanks in advance,

Veliremus

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

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Mike 3 · May 07, 2010 at 10:38 AM

it doesn't all have to fade - if you change GUI.color to a faded value, call the DrawTexture function, then change GUI.color to Color.white, it'll fade only that single object

edit:

GUI.DrawTexture(Rect(0, 0, screenwidth, screenheight), backgroundTexture);

GUI.color = new Color(1,1,1,0.5); GUI.DrawTexture(Rect(0, 0, screenwidth, screenheight), fadeOutTexture); GUI.color = Color.white;

GUI.DrawTexture(Rect(100, 100, 100, 100), anotherTexture);

that will draw a background, followed by a faded texture, followed by a smaller object on top of it

Comment
Add comment · Show 4 · 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 Story Specialist · May 07, 2010 at 10:44 AM 0
Share

I don't quite follow, can you please give me a script example?

avatar image Story Specialist · May 07, 2010 at 01:06 PM 0
Share

Thanks for the quick response. But that keeps the texture faded, right? What I mean is actually fading in and out. For example, I want my game to switch scenes (not Unity scenes) by fading out and into the new scene, but without fading the GUI out and in.

avatar image Mike 3 · May 07, 2010 at 03:46 PM 0
Share

Same idea - you just need to change the alpha value for the GUI.color for each texture you're fading out/in

avatar image Story Specialist · May 10, 2010 at 09:10 AM 0
Share

But doesn't this take out the animation? $$anonymous$$aybe I'm acting like a noob, but I don't understand how I would call my fade function from another script. To eloborate, I write all my scenes in X$$anonymous$$L, and my parser reads the tags. When it sees example for instance, it draws the background. The same thing would happen with the fades, but I don't see how I can do this. Sorry, very inexperienced with Javascript.

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

Timer Between Labels 2 Answers

How Would I Make A GUI Label Fade After A Certain Amount Of Time? 1 Answer

Setting Scroll View Width GUILayout 1 Answer

Fade multiple GuiTextures in ONE Javascript 1 Answer

What's wrong with my function? It keeps telling me 'loseText' is not a member of 'UnityEngine.GUIText'. Please help, please and thank you! 0 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