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 /
  • Help Room /
avatar image
0
Question by paco morales · Oct 21, 2015 at 01:07 PM · androidjavascriptgui

I want to change the transparency or visibility (alpha) with a UI button

Hi, I am trying to enable an UI Button, but I cant....I want to enable my script with the function (On Click) adding the Update function. But it doesn't work.

Basically I want to change the transparency or visibility (alpha) with this button

Please any advice is more than welcome.

 private var a : float = 1; // alpha starts at 1
 var fadeSpeed : float = 2;
 private var Green : b!oolean = true;
  
 function Update(){
   
     if(Green == true){
         GetComponent.<UI.Text>().material.color.a = Mathf.Lerp(GetComponent.<UI.Text>().material.color.a, 1, Time.deltaTime * fadeSpeed);
 
     }else{
 
         GetComponent.<UI.Text>().material.color.a = Mathf.Lerp(GetComponent.<UI.Text>().material.color.a, 0, Time.deltaTime * fadeSpeed);
     }    
 }![alt text][1]


[1]: /storage/temp/56618-capture.jpg

capture.jpg (88.6 kB)
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 allenallenallen · Oct 21, 2015 at 01:14 PM

OnClick() only works with a function you created yourself.

Make a new function called ChangeAlpha() or soemthing and copy the contents in Update() into it.

 function ChangeAlpha(){
     // if(Green == true){...... blah blah blah blah
 }

Then you'll see the option to call it in the editor menu.

On a side note, you don't need to write "Green == true". You just need to write "Green"

 if (Green){
 }
 else{
 }
Comment
Add comment · Show 8 · 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 paco morales · Oct 21, 2015 at 02:47 PM 0
Share

Hi allenallenallen,

Thanks for your replay.

I did make the changes, but when I hit the button the alpha only change a little, I have to hit the button several times in order to make the text invisible.

Is there other think I can do?

Thanks for your help!

 private var a : float = 1; // alpha starts at 1
 var fadeSpeed : float = 1;
 private var Green : boolean = true;
  
  
 function ChangeAlpha(){
   
     if(Green){
 
         GetComponent.<UI.Text>().material.color.a = $$anonymous$$athf.Lerp(GetComponent.<UI.Text>().material.color.a, 0, Time.deltaTime * fadeSpeed);
     }
     else{
 
         GetComponent.<UI.Text>().material.color.a = $$anonymous$$athf.Lerp(GetComponent.<UI.Text>().material.color.a, 1, Time.deltaTime * fadeSpeed);
     }    
 }
  
  
avatar image allenallenallen paco morales · Oct 21, 2015 at 03:31 PM 0
Share

Do you want it to happen instantly or fade in/out?

Fade: http://answers.unity3d.com/questions/225438/slowly-fades-from-opaque-to-alpha.html

avatar image allenallenallen allenallenallen · Oct 22, 2015 at 12:38 AM 1
Share

Use a simple boolean.....

Learn some simple coding even if you're strictly a 3D modeler.

 if(Green){
      GetComponent.<UI.Text>().material.color.a = 0;
      Green = false;
 
  }
  else{
      GetComponent.<UI.Text>().material.color.a = 1;
      Green = true;
 
  }

Show more comments
avatar image paco morales · Oct 21, 2015 at 02:50 PM 0
Share

Basically I want to hit one time the button and make invisible the text and hit again the button and make the text visible again.

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

44 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 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 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

أنجازات غير مسبوقة؟؟!!توكيل كاريير +بالاسكندرية 01286629661 0 Answers

java.lang.ClassNotFoundException: com.google.android.gms.games.Games 1 Answer

Im trying to control a 3d player with 4 GUI buttons and Im trying to attach the script below to the onClick function in the button, but my script isnt working can some help? 0 Answers

Scrolling as Shown in This Video 0 Answers

Trying to move UI Elements but they are not working 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