- Home /
ERROR BCE0051: Operator + cannot be used with a left hand side of type 'UnityEngine.Vector3' and a right hand side of type 'float'.
Hi, I am working at my game until this error showed up. I have this code for moving a object:
var straal;
function Update () {
var straal = 3.0;
transform.position += straal;
}
and this error:`Assets/Piss.js(5,22): BCE0051: Operator '+' cannot be used with a left hand side of type 'UnityEngine.Vector3' and a right hand side of type 'float'. ` anyone knows the solution?
Added code formatting for you, please use the 10101 button to have code formatting. Also searching this site for BCE0051 would have given you an idea how to solve this.
Well what did you envision the result of adding 3.0 to a Vector3 position would be? I'm just as confused as the compiler on that one.
Linus' answer is correct, please checkmark it.
Answer by Linus · Mar 02, 2014 at 11:09 PM
You need to choose what value you want to add straal to. transform.position is a Vector3. It consists of
transform.position.x transform.position.y transform.position.z
You can do
transform.position.x += stral;
transform.position += Vector3(1,1,1); //This is Vector3(x,y,z);