Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 MattSawrey · Apr 28, 2014 at 10:02 PM · colorgui-textdisappearing

Script to change colour makes GUItext invisible. Any idea why?

I'm using the following script to interpolate between multiple colours for some GUItext in a scene. But for some reason, the GUItext I attach this to disappears when I hit play. I've testing every otehr factor that I can think of, and it only seems to disappear when this script is attached and active. I've also attached it to a number of different objects in my scene, and modified it to change the colour of their rendering material and the same thing happens - the object dis appears when I hit play. Everything looks fine in the inspector, the color under the GUItext component changes as expected, etc. The object just doesn't appear in play.

If anyone can spot the error, I'd be very grateful.

 public class ColourController : MonoBehaviour 
 {
 
     public Color[] colors;
     
     public int currentIndex = 0;
     private int nextIndex;
     
     public float changeColourTime = 2.0f;
     
     private float timer = 0.0f;
 
     //access the gameobject
     GUIText titleColour;
     
     void Start() 
     {
         //access the gameobject
         titleColour = GetComponent<GUIText>();
 
         if (colors == null || colors.Length < 2)
         {
             Debug.Log ("Need to setup colors array in inspector");
         }
         
         nextIndex = (currentIndex + 1) % colors.Length;   
     }
     
     void Update() 
     {
         timer += Time.deltaTime;
 
         //creates a timer that loops from 0 to 1 and makes things happen when it reaches 1
         if (timer > changeColourTime) 
         {
             currentIndex = (currentIndex + 1) % colors.Length;
             nextIndex = (currentIndex + 1) % colors.Length;
             timer = 0.0f;        
         }
 
         titleColour.color = Color.Lerp(colors[currentIndex], colors[nextIndex], timer / changeColourTime );
     }
 
 }

Thanks, Matt

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
6
Best Answer

Answer by robertbu · Apr 28, 2014 at 10:06 PM

In the Inspector, go to your array of colors. Click each color to bring up the color picker and change the value of 'A' to 255.

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
avatar image
1

Answer by MattSawrey · Apr 29, 2014 at 04:52 PM

What a stupid mistake! Thanks for the answer.

Matt

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
avatar image
0

Answer by SleazyDutcham · Oct 07, 2017 at 01:01 AM

Lol wow just had the same issue. Thanks @robertbu and @matski53 .

Is this really a "mistake" though? Why does the editor default to full transparency instead of full opaque? To me, seems illogical to have the editor behave that way.

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 WaqasHaiderDev · May 18, 2021 at 06:47 AM 0
Share

Agree with you.

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

21 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

Related Questions

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

Changing two different objects renderer colour 1 Answer

How can i adjust colour of Editable Copy of font? 1 Answer

UIMask and UIText problem 0 Answers

A Javascript trying to access an image effect C# script 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