The following:
for (i = 0.51f; i > 0.0f; i -= Time.deltaTime * 1f/(transitionSpeed * 2f))
{
gameObject.GetComponent<GUITexture>().color.a = i;
}
is giving me the error:
“Cannot modify a value type return value of `UnityEngine.GUITexture.color’. Consider storing the value in a temporary variable”
I’m having trouble nailing this one down- any keen eyes out there?
Many thanks-
Orion
you can not use color.a to assign something.
.color is a property and Color is a struct.
as such you need to copy the color into a Color object, modify a and store it back into .color
Is there any reason this would work in JS and not C#?
I know it seems strange, but that exact same thing seems to be working in a JS script I found:
for (i = 0.51; i > 0.0; i -= Time.deltaTime * 1/(fadeTime*2)) {
guiTexture.color.a = i;
yield;
}
I’m not that knowledgable about JS- is there a reason it would work there and not in my script. Thanks a lot!
O
I think it’s because your using GetComponent function in the C# example and trying to modify the return value without it being assigned. In the JS your directly altering the value.
As the error says, in C# you have to use a temporary variable.
var temp = guiTexture.color;
temp.a = i;
guiTexture.color = temp;
That actually still happens in Javascript, but it’s behind the scenes so you don’t have to do it yourself.
By the way, you don’t need “gameObject.GetComponent()”, you can just use “guiTexture”.
–Eric