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
1
Question by ClockParadoX · Oct 21, 2011 at 04:19 AM · materialcolormaterialsalphaguitext

How do I get the current alpha value of a material?

I've got a GUIText that I'm trying to get the current alpha value of before I start a fade. I'm having trouble with the code below always returning 0.

 public float CurrentMessage1Alpha;
     void Update () {
     GameObject Message1 = GameObject.Find("Messages1");
     CurrentMessage1Alpha = Message1.guiText.material.color.a;
     }

What am I doing wrong?

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
1

Answer by jahroy · Oct 21, 2011 at 04:59 AM

I believe you get to the material by accessing the GUIText's transform's renderer...

Like this:

 if ( Message1.guiText.transform.renderer != null ) {
     print(Message1.guiText.transform.renderer.material.color.a);
 }

OR...

After looking at the documentation some more, it looks like you might want to try the GUIText.renderer if that doesn't work...

if ( Message1.guiText.renderer != null ) {
    print(Mesasge1.guiText.renderer.material.color.a);
}

I've never used a GUIText, but I'm pretty sure one of those will work.

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 ClockParadoX · Oct 21, 2011 at 05:32 AM 0
Share

Hmm, no luck with either of those. I get this error: $$anonymous$$issingComponentException: There is no 'Renderer' attached to the "$$anonymous$$essages1" game object, but a script is trying to access it. You probably need to add a Renderer to the game object "$$anonymous$$essages1". Or your script needs to check if the component is attached before using it.

avatar image jahroy · Oct 21, 2011 at 05:48 AM 0
Share

Check my other answer...

Also make sure you add a $$anonymous$$aterial to your GUITexture in the Inspector.

avatar image
0

Answer by jahroy · Oct 21, 2011 at 06:01 AM

Are you sure your alpha value isn't actually equal to 0?

I just created a GUIText in my game to test this...

First I added a material to the GUIText in the Inspector.

Then I added the following script to the object with the GUIText attached:

function Update () { var theTex : GUIText = transform.GetComponent(GUIText);

 var theMat  :  Material  =  theTex.material;

 Debug.Log("Material " + theMat.name + "has alpha " + theMat.color.a);

}

It prints the name of my material and the value 1 over and over.

This makes me wonder... Is your value actually 0?

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Material doesn't have a color property '_Color' 4 Answers

Modifying the Arial material for fading GUITexts 1 Answer

Changing two different objects renderer colour 1 Answer

Can't animate Material.Color properties 3 Answers

Lights colored like material 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