- Home /
Simple C# problem
Hi,
I want to switch from JS to C# and am totally new to C# scripting.
I can't figure out why this expression is invalid for C#:
transform.Translate(Vector2((newRotation-oldRotation)*0.01,0));
old/newRotation are float variables.
I get the following errors:
Expression denotes a 'type', where a 'variable', 'value' or 'method group' was expected.
The best overloaded method match for 'UnityEngine.Transform.Translate(UnityEngine.Vector3)' has some invalid arguments.
Argument '#1' cannot convert 'object' expression to type 'UnityEngine.Vector3'
All these errors occurred as well when I tried to use a Vector3 with additional z-value of 0.
Thanks for your help! :)
Answer by Landern · Jun 17, 2014 at 12:29 PM
You new to put "new" in front of Vector2, also floats with decimals need an f at the end in c#:
transform.Translate(new Vector3((newRotation-oldRotation)*0.01f,0));
Also Translate takes a Vector3
Vector3 Documentation, including the 2 float constructor
And @$$anonymous$$aeh also don't forget to write 'f' at the end of values you might be assigning to your newRotation and oldRotation variable in your code. Just a heads up!
@Harshad$$anonymous$$ is correct and its a very small detail that can frustrate you during debugging.
Answer by tanoshimi · Jun 17, 2014 at 12:33 PM
You've got several problems here:
"Expression denotes a type" is because you haven't written
new
before Vector2"UnityEngine.Transform.Translate(UnityEngine.Vector3) has some invalid arguments" is because you're passing a Vector2 instead of a Vector3.
Try:
transform.Translate(new Vector3((newRotation-oldRotation)*0.01f, 0, 0));
Your answer
![](https://koobas.hobune.stream/wayback/20220613151747im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Script error about the semicolon. 1 Answer
GameObject[] Issues 1 Answer
How do I inherit certain varibles and functions from another script. 1 Answer
Checking null variable error 3 Answers