- Home /
Operator '-' cannot be used ... error
This is my error I think it effects the lines
guitex.pixelInset.x = Screen.width - achievementTex.width - edgeMargin;
guitex.pixelInset.x = Screen.width - achievementTex.width - edgeMargin;
Operator '-' cannot be used with a left hand side of type 'int' and a right hand side of type 'Object'.
pragma strict
var firstStepTex:Texture;
private var firstStepTaken:boolean;
private var edgeMargin;
function Start(){
edgeMargin = Screen.width * .01;
}
function playerMoved(){
if(!firstStepTaken){
unlockAchievement(firstStepTex);
firstStepTaken = true;
}
}
function unlockAchievement(achievementTex:Texture){
var go:GameObject = new GameObject("Achievement Object");
go.transform.position = Vector3(0,0,0);
go.transform.localScale = Vector3(0,0,0);
var guitex:GUITexture = go.AddComponent(GUITexture) as GUITexture;
guitex.texture = achievementTex;
guitex.pixelInset.width = achievementTex.width;
guitex.pixelInset.height = achievementTex.height;
guitex.pixelInset.x = Screen.width - achievementTex.width - edgeMargin;
guitex.pixelInset.x = Screen.width - achievementTex.width - edgeMargin;
}
perhaps explictly type edge$$anonymous$$argin
private var edge$$anonymous$$argin:float;
you probably already know but isn't your second line of ;pixel inset.x supposed to be height and .y ,and it looks like its in the wrong row ?
Answer by Eric5h5 · Oct 07, 2012 at 06:11 PM
You must define the type of all your variables, either explicitly or by supplying a value. This:
private var edgeMargin;
should not be done, since it has no type.
Your answer
![](https://koobas.hobune.stream/wayback/20220613082018im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How to access variables between scripts in unity JavaScript? 3 Answers
How do I access a script variable from a class defined within that script? 1 Answer
variable scope problem 1 Answer
Can 2 scripts attached to one object communicate with each other? 2 Answers
Syntax Help: JS ---> Reference a variable in another JS script 1 Answer