- Home /
Editing color with C# script
Hi there,
I'm trying to use an UPNP Device to interact with my Unity Scene. I manage to do it but I encounter an error in the setter :
public void CubeService_setColor(DvCubeService.Enum_color newColor)
{
CubeService.setColor(newColor); // this allow me to save the color value in the script
switch (newColor.ToString())
{
case "red":
gameObject.renderer.material.color = Color.red;
break;
case "blue":
gameObject.renderer.material.color = Color.blue;
break;
case "green":
gameObject.renderer.material.color = Color.green;
break;
default: break;
}
}
The error is :
InternalGetGameObject can only be called from the main thread.
Constructors and field initializers will be executed from the loading thread when loading a scene.
Don't use this function in the constructor or field initializers, instead move initialization code to the Awake or Start function.
Even if I initialize the value in the start function this error is still there...
Looking on other post I found a solution mooving the switch to the Update function and use a Getter for the value. And it actually work.
But for what I need to do after, I would prefere not using Update... Is there an other solution to invoke the color change only once in the setter ?
Thank you.
Your answer
Follow this Question
Related Questions
Game ruined when updated to unity 3.2 0 Answers
Time.time button delay trick causing NaN 0 Answers
HELP! Most GUI Text mysteriously nudged upwards after update.. 1 Answer
moved project to new version of Unity, Weird stylehseet error 1 Answer
Are these problems are related to a NGUI change (update) 1 Answer