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 Wettechsupport · Jul 10, 2013 at 09:07 PM · editorclassblack

Color set to black even though it's set by the editor

You can view the script if you want, but it doesn't help. If I set the color in the script instead of the editor it works fine.

Basically the game object holds an array of this class (in case I make an object with multiple materials later)

 public class MaterialColorFadeHandler
 {
     public var delay : double = 1.0;
     public var startColor : Color = new Color();
     public var endColor : Color = new Color();
     
     private var myColor : Color = new Color();
     private var runTime : double = 0.0;
     private var onStart : boolean = true;
     private var difference : Color = new Color();
     
     
     function MaterialColorFadeHandler()
     {
         if(delay == 0.0)
             delay = 1.0;  //Don't let delay be 0
         myColor.r = startColor.r;
         myColor.g = startColor.g;
         myColor.b = startColor.b;
         myColor.a = startColor.a;
     
         difference.r = endColor.r - startColor.r;
         difference.g = endColor.g - startColor.g;
         difference.b = endColor.b - startColor.b;
         difference.a = endColor.a - startColor.a;
         
         Debug.Log("Start color: " startColor.ToString());
         Debug.Log("End color: " endColor.ToString());
     }
     
     function runFade(t : double)
     {
         if(onStart) //Go forwards
         {
             runTime += t;
             if(runTime > delay)
                 onStart = false;
         }
         else    //Go backwards
         {
             runTime -= t;
             if(runTime < 0.0)
                 onStart = true;
         }
         
         
         //Alright, now we calculate the color.
         var perc : double = runTime / delay;
         if(difference.r != 0.0)
             myColor.r = startColor.r + (difference.r * perc);
         if(difference.g != 0.0)
             myColor.g = startColor.g + (difference.g * perc);
         if(difference.b != 0.0)
             myColor.b = startColor.b + (difference.b * perc);
         if(difference.a != 0.0)
             myColor.a = startColor.a + (difference.a * perc);
         
         
     }
     
     function getColor() : Color
     {
         return myColor;
     }
     
 }


Anyway, the color fade (as I mentioned earlier) works when I set the color in the constructor, but not when I set it in the editor (it goes to black, default)

Does anyone know why?

Comment
Add comment · Show 2
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 perchik · Jul 10, 2013 at 11:01 PM 0
Share

Can you post the code that actually has the array of this class? $$anonymous$$y instinct is that you're initializing this class somewhere, which sets the color to black, ins$$anonymous$$d of just taking in the color from the editor.

avatar image Wettechsupport · Jul 11, 2013 at 06:06 PM 0
Share

Certainly. The code that calls the class is here: #pragma strict

 var list : $$anonymous$$aterialColorFadeHandler[];
 
 
 
 
 function Start () {
     
 }
 
 function Update () {
     var i : int;
     for(i = 0; i < list.Length; i++)
     {
         list[i].runFade(Time.deltaTime);
         renderer.materials[i].SetColor("_Color", list[i].getColor());
     }
     
     
 }

0 Replies

· Add your reply
  • Sort: 

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

16 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

Related Questions

Better way to call function from another script from editor script? 1 Answer

Can I write a script to rename objects as I create them? 1 Answer

Non-MonoBehaviour class exists in scene, constantly calling itself 2 Answers

Fastest way to instantiate and move multiple game objects in the editor 3 Answers

If there is only 1 instance of a class, should it be Static? - C# 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