- Home /
Operator + cannot be used to combine Object and Int
Hi there, I'm just watching this video: http://vimeo.com/channels/151501/17058866
The series is very good so far, but I've come to a point, where the maker of the video does something, which doesn't work at my unity:
var box;
box = "small box ";
boxNumber = 3;
print (box + boxNumber);
It should print "small box 3"but I get the error: "Operator '+' cannot be used with a left hand side of type 'Object' and a right hand side of type 'int'."
Which I totally understand as I come from php, where variables are "connected" via "." ($first.$last)
Why doesn't it work?
In particular, it's not working because the compiler isn't able to infer the type of `box` (you can fix this by specifying the type, or assigning a value while declaring it).
UnityScript enforces strict typing if your script contains `pragma strict;`, which has been the default for the past few releases. The tutorial you're following might have been using dynamic typing, which is sometimes easier to work with but has a few drawbacks (sometimes hurts performance, doesn't catch some problems until code is run).