- Home /
Vector3 and Object build errors
Building an fps game for the android/ios, the following two errors appeared when trying to compile the code:
Assets/ZombieScripts/FemZombiev1_AI.js(183,29): BCE0051: Operator '*' cannot be used with a left hand side of type 'UnityEngine.Vector3' and a right hand side of type 'Object'.
Assets/ZombieScripts/FemZombiev1_AI.js(186,39): BCE0051: Operator '*' cannot be used with a left hand side of type 'Object' and a right hand side of type 'float'.
Am i right to understand that this error relates to the calling of the object within the script? All variables are defined within the same script, and compiled correctly for the web versions.
Or if not, can anyone direct me on what the issue is, and ideas on how to fix it,
Thanks, D
Well, presumably it's because you're attempting to multiply an 'Object' with a Vector3 or a float! In this case, I'd blame Javascript's fuzzy typing- try forcing each member to have an explicit type. Could you post the specific lines involved there? The problem might be somewhat more in-depth. Just knowing the name of the error is not enough to be able to fix it, only enough to know what is causing the problem.
Answer by Caiuse · Nov 15, 2011 at 11:16 AM
I found that when programming iOS game in Unity you have to be a little more precise with you declarations.
the variables that you are trying to * have to have a type declared.
for example :
for(element in anArray){
var result = element * 10.0;
}
will not work, where as this will:
for(element : float in anArray){
var result = element * 10.0;
}
Hope this helps - Caius
Answer by daves · Nov 15, 2011 at 11:48 AM
The two lines of code which present the two errors:
The 'Object' related error:
direction = forward * speed * speedModifier;
GetComponent (CharacterController).SimpleMove(direction);
The float related error:
SendMessage("SetSpeed", speed * speedModifier, SendMessageOptions.DontRequireReceiver);
Thansk for advice so far, will continue to have a look at this, as these two errors are present in 22 other files using a similar structure.
Thanks, D
Well, as Caius said, make sure that all your variables are being explicitly typed! Where you would have used
var speed = 100;
ins$$anonymous$$d explicitly make it a float-
var speed : float = 100;
This way, you won't have compile errors telling you that you are using the wrong types.
tl;dr This is why you should use C#, this stuff is frustrating as hell to deal with.