0
votes

I want to apply a texture or a color on a game object. I wrote this code so far but the color part is not working. The texture is applied, so at least something is right. Depends of the type of the object i am applying a texture or a color, not both at the same time.

If i play the scene i can see a new material getting assign (i see it in the inspector panel) but with a white color.

GameObject o = GameObject.Find(items[i].name + "/" + ifv.field_details.name);
if (o != null){
    if (ifv.field_details.type_id.Equals(Strings.colorType)){
        //set the color
        string[] c = ifv.value.Split(',');
        Color color = new Color(float.Parse(c[1]),float.Parse(c[2]),float.Parse(c[3]),float.Parse(c[0]));
        Material material = new Material(Shader.Find("Diffuse"));
        material.color = color;                         
        o.renderer.material = material;
    }
    if (ifv.field_details.type_id.Equals(Strings.textureType)){
        //set the texture
        string url = Strings.texturesHost + ifv.value;
        WWW www = new WWW (url);
        yield return www;
        o.renderer.material.mainTexture = www.texture;
    }
}

Any idea why the color if statement is not working ?

1
You may have better luck getting Unity questions answered on their dedicated Q&A site: answers.unity3d.com/index.htmlAdrian
i found the answer : i have to divide each number by 255 to work. if someone post it as an answer i will accept it.sebastian.roibu
You should post it yourself and accept. Then we can up vote it :)Kay

1 Answers

1
votes

The answer was : divide each number by 255. I don't know the explanaition but it looks that new Color() expects the parameters to be between 0 and 1.