Quantcast
Channel: Questions in topic: "error"
Viewing all articles
Browse latest Browse all 7934

Editing color with C# script

$
0
0
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.

Viewing all articles
Browse latest Browse all 7934

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>