- Home /
Operator '*' cannot be used with a left hand side of type 'int' and a right hand side of type 'Object'.
I don't know why is code isn't working, I made it and I don't know why.
#pragma strict
function TimesByTwo(YourNumber){
var NewNumber = 2 * YourNumber;
return NewNumber;
};
TimesByTwo(5);
It keeps saying, "Operator '*' cannot be used with a left hand side of type 'int' and a right hand side of type 'Object'."
If you know why is happening and How I can fix it please tell me. Thanks!
Please read how to format code. I've fixed your question so it's readable.
Answer by Graham-Dunnett · Sep 05, 2014 at 09:24 PM
YourNumber
doesn't have a type, so it's treated as an Object
. There is no operator *
which can multiply an integer by an Object
. Tell the compiler that YourNumber
is an integer.
function TimesByTwo(YourNumber : int){
Your answer
![](https://koobas.hobune.stream/wayback/20220613162402im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Can someone help me fix my Javascript for Flickering Light? 6 Answers
Quit on Touch Script errors (Js) 1 Answer
(C# and Java)Unable to give the Damage from enemy bullet script to Player Health. 3 Answers
Script is causing crashes and i Don't know what to do. 2 Answers
I cant open any scripts. 0 Answers