- Home /
Erroe when resizing GUITextures in C# file
Hi guys,
I have an in-game store that uses GUITexture objects for the UI buttons. This is the relevant code, from GameStore.cs:
Code:
public class GameStore : MonoBehaviour {
public GUITexture storeButton;
public GUITexture oneUseButton;
public GUITexture fiveUseButton;
public GUITexture tenUseButton;
public GUITexture twentyUseButton;
...
void Awake () {
...
// Resize images to 1/2 size on non-retina devices
...
storeButton.transform.localScale = Vector3(0.5, 0.5, 0.5);
oneUseButton.transform.localScale = Vector3(0.5, 0.5, 0.5);
fiveUseButton.transform.localScale = Vector3(0.5, 0.5, 0.5);
tenUseButton.transform.localScale = Vector3(0.5, 0.5, 0.5);
twentyUseButton.transform.localScale = Vector3(0.5, 0.5, 0.5);
...
}
...
}
The code is supposed to draw the GUITextures at 1/2 their length and width when displayed on a non-retina iOS device (iPhone 3GS, 1st and 2nd-gen iPad, iPad Mini), but the code instead results in the following error:
error CS0119: Expression denotes a `type', where a `variable', `value' or `method group' was expected
The standard fix is to use the term "new" somewhere, but I'm not sure how it applies here (since the public variables are set in the inspector). What should I do?
MachCUBED
just FWIW, not to sound like a broken record but many people use 2DToolkit (or any similar competitive product) for this sort of thing. It is unbelievably time-saving.
Answer by Chronos-L · Apr 05, 2013 at 05:34 AM
This line is okay in uJS:
storeButton.transform.localScale = Vector3(0.5, 0.5, 0.5);
But in C#, it should be:
storeButton.transform.localScale = new Vector3(0.5f, 0.5f, 0.5f);
0.5
in uJS is considered to be a float while in C# 0.5
is a double, you need to write 0.5f
in C# for it to be a float
Your answer
Follow this Question
Related Questions
What am I doing wrong? C# 1 Answer
Setting Scroll View Width GUILayout 1 Answer
Multiple Cars not working 1 Answer