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 Stat Phantom · Mar 20, 2015 at 11:28 AM · c#buttonalphawaitforsecondsdelay

check alpha of gameObject C#

I have a button that fades into screen using leanTween, however I want to be able to only make the button click-able once it has finished fading it. I saw that the delay functions delay the whole scene so it will delay the fading as well.

I was thinking of using the update() function to check the alpha of the button till it is maxed (or == 1f) but cant find out how to do this, any help please?

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

3 Replies

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

Answer by eezSZI · Mar 20, 2015 at 01:06 PM

If you are using a new UI button, you could find the targetGraphic and use the built in crossfade. Or do it manually. Based on your comment code it looks like you are use the UI.Button, in which case it usually has a reference to a Graphic.

 UnityEngine.UI.Button b = new UnityEngine.UI.Button();
 b.targetGraphic.CrossFadeAlpha(0, .6f, true);
 
 // or check/set alpha/color directly
 b.targetGraphic.color.a = 0;
Comment
Add comment · Show 1 · 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 Stat Phantom · Mar 21, 2015 at 03:34 AM 0
Share

this is the best way to do what I wanted so I accepted this as the answer, however thanks for the other comments they did help as well :)

avatar image
1

Answer by hav_ngs_ru · Mar 20, 2015 at 11:53 AM

renderer.material.color.a - for gameobjects

GUI.color.a - for GUI elements

and... taadaaaaa! LeanTween.alpha for leanTween

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 Stat Phantom · Mar 20, 2015 at 12:10 PM 0
Share

thanks, seems to be working however the effect is not working like I wanted, the button is ALWAYS active. this is my code snippet.

 void Start () {
     this.GetComponent<Button> ().interactable = false;
     fadeIn();
 }

 void Update() {

          if (GUI.color.a == 1f) {
       this.GetComponent<Button>().interactable = true;
      }
 }

I feel like I need to pass in another variable to the if statement but cant work it out.

avatar image hav_ngs_ru · Mar 20, 2015 at 12:50 PM 0
Share

seems like you use new UI, but trying to get an old GUI.color

avatar image
1

Answer by DiegoSLTS · Mar 20, 2015 at 01:07 PM

I've never used LeanTween, but looking at the documentation it has a LeanTween.isTweening method that looks like it would return false once the tween has finished.

Try checking if the tween is still tweening instead of checking the alpha, it makes more sense if you think about it, you just want to know if it finished, and with this method you can change the final alpha value if you need to and everything should still work.

Comment
Add comment · Show 1 · 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 Stat Phantom · Mar 21, 2015 at 03:30 AM 0
Share

sweet that works fine, however I would like to make the button active just before it maxes 1f alpha so > .9f due to no visual difference between being active or not. but up vote for a working answer but just won't work for me.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

How would I add a scene delay timer to my script? 1 Answer

Multiple Cars not working 1 Answer

OnTriggerEnter launching a delayed tween 1 Answer

How do i add a delay to how often a unity ui button may be used? 1 Answer

Distribute terrain in zones 3 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