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 dawgtothebone · Jan 12, 2013 at 07:46 PM · guitexturecoroutinesfadefadeout

Fading out GUITexture - I need help with timer function that will control the speed of fading out

Hi Everyone,

I am writing a script to fadeout a GUITexture (and a few other things) after an input from the keyboard has been received. I am having trouble with decreasing the alpha value for the GUITexture slowly, at the moment the GUITexture fades out almost instantly. I have seen similiar questions on this topic and the solutions seems to be with using co-routines. I do not understand how to write coroutines in JS.

My fadeout function is similiar to Zerofractals fade function. I have also looked at Mathf.Lerp and mathf.SmoothDamp, however I could not achieve what I wanted. Perhaps I am using the functions incorrectly or not as intended. Any help on this would be much appreciated.My code is as follows

 var scrollTexture:GUITexture;
 var messageToGamePlayer: GUIText;
 var scrollText: GUIText;
 
 var fadeDuration:float = 0.5;
 var alpha:int;
 private var timeLeft:float=0.5;
 
 function Start () {
     scrollTexture.enabled=false;
     messageToGamePlayer.enabled=false;
     scrollText.enabled=false;
 }
 
 function OnTriggerEnter(){
     this.renderer.enabled=false;
     scrollTexture.enabled=true;
     messageToGamePlayer.enabled=true;
     scrollText.enabled=true;
 }
 
 function Update (){
     if (Input.GetButton ("Jump")){
         fadeOut();
 //        disableGUITexture();
 //        Destroy(gameObject);
     }
 }
 
 function fadeOut(){
        if(scrollTexture.color.a > 0){
        timeLeft = timeLeft - Time.deltaTime;
        alpha = (timeLeft/fadeDuration);
        scrollTexture.color.a=alpha/2;
       } 
    }
 
  function disableGUITexture(){
     scrollTexture.enabled=false;
     messageToGamePlayer.enabled=false;
     scrollText.enabled=false;
 }

Thanks in Advance.

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
0

Answer by youngapprentice · Jan 12, 2013 at 08:04 PM

A Coroutine is a function that shares control with the rest of the script, and releases control on the 'yield' statement.

To make a coroutine, you just make a new function and make sure it has a yield (otherwise it wouldn't need to be a coroutine) then us the code 'StartCoroutine( MyFunction( params ));'

A Lerp script I use is this:

 private var lerp = 0.0;
 private var track = 0.0;
 private var value : float;
 var time : float;
 
 
 function lerpPos(){
     if(track < time){
         track += Time.deltaTime;
         lerp = track/time;
         value = Mathf.Lerp(start, end, lerp);
     }
 }

And obviously your value would be the alpha. Another possibility for you is iTween.FadeTo()

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

Changing a GUITexture's alpha gives me no effect in game. 0 Answers

How to edit a fade screen script to change color on demand? 2 Answers

Fade script working but I can't 'see' it working? (Solved) 1 Answer

Basic screen fader fading too quickly 1 Answer

Fade logo before main menu 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