The type `Color' does not contain a constructor that takes `3' arguments

I recently downloaded MaterialUI for free online from GitHub. When I tried to use it, it gave me several errors. They all say:

The type Color' does not contain a constructor that takes 3’ arguments

One line of code where an error is coming from is this:

m_RGBImage.color = new Color(m_sliderR.value/255f, m_sliderG.value/255f, m_sliderB.value/255f);

I am running Unity 5.3.4f1 Personal Edition. Could anyone help me solve this issue?

Have you tried adding an alpha value

That should work. Is it possible you have another class named “Color” in your project that’s hiding the Unity class?

Well, this is what the whole script looks like:

using UnityEngine;
using UnityEngine.UI;
using MaterialUI;

public class Example05 : MonoBehaviour
{
 #region groupRGB
 [SerializeField] private Text m_sliderTextR;
 [SerializeField] private Text m_sliderTextG;
 [SerializeField] private Text m_sliderTextB;
 [SerializeField] private Slider m_sliderR;
 [SerializeField] private Slider m_sliderG;
 [SerializeField] private Slider m_sliderB;
 [SerializeField] private Image m_RGBImage;

 void Awake()
 {
 onSliderRValueChanged();
 onSliderGValueChanged();
 onSliderBValueChanged();
 }

 public void onSliderRValueChanged()
 {
 m_sliderTextR.text = m_sliderR.value.ToString();
 updateRGBImage();
 }
 
 public void onSliderGValueChanged()
 {
 m_sliderTextG.text = m_sliderG.value.ToString();
 updateRGBImage();
 }

 public void onSliderBValueChanged()
 {
 m_sliderTextB.text = m_sliderB.value.ToString();
 updateRGBImage();
 }

 private void updateRGBImage()
 {
 m_RGBImage.color = new Color(m_sliderR.value/255f, m_sliderG.value/255f, m_sliderB.value/255f);
 }
 #endregion
}

This.

The docs list a three parameter constructor for the Color class.

Do a search of the entire project. Is there another class called Color?

I’m pretty sure no… Here is a photo of me searching for “Color” (Attached Below)

2662865--187785--Screen Shot 2016-06-03 at 11.08.28 AM.png

What is in “Color.cs”? You sure it’s not a MonoBehaviour named “Color”?

2 Likes

Try adding this to the top of your file:

using Color = UnityEngine.Color;

That will make sure Color resolves to the version in UnityEngine. My guess is the same as others… the problem is that someone created a Color class and didn’t put it in a namespace, which means it goes in the Global namespace and ruins everyone’s day.

Okay… I did that. I got this error now:

Assets/MaterialUI/Examples/Scripts/05 - Sliders/Example05.cs(44,40): error CS0576: Namespace global::' contains a definition with same name as alias Color’

That means there is definitely another class named “Color” in your project. Like I mentioned, “Color.cs” is probably a good guess for where it is.

2 Likes

Okay, that all worked… Thanks!