- Home /
add a float and object
I'm trying to add the accelerometer value and collect the up but keep getting this error:
Operator '+' cannot be used with a left hand side of type 'float' and a right hand side of type 'object'
Do I need to cast something?
y = iPhoneInput.acceleration.z + y;
Answer by qJake · May 01, 2010 at 10:42 PM
What programming language are you using? You can't just do "y = something", you have to instantiate your variable first.
// C# float y; y += iPhoneInput.acceleration.z;
// JS var y : float; y += iPhoneInput.acceleration.z;
If you're accumulating your variable, you might also want to make your "y" variable a global variable inside your class.
Sorry about that, I figured it was assumed that it was instantiated. I initially was using '+=' but was getting an error that I later discovered was the result of my trying to add and object and a number. Thanks for your help.
Your answer
![](https://koobas.hobune.stream/wayback/20220612204316im_/https://answers.unity.com/themes/thub/images/avi.jpg)