I have a simple script working in JS move the player to specific vector3 and I’m having issues converting to C#.
Any help would be greatly appreciated.
Thanks!
if(shieldHealth <= 0) {
transform.position = Vector3(0, 15, 0);
I have a simple script working in JS move the player to specific vector3 and I’m having issues converting to C#.
Any help would be greatly appreciated.
Thanks!
if(shieldHealth <= 0) {
transform.position = Vector3(0, 15, 0);
if(shieldHealth <= 0) {
transform.position = new Vector3(0, 15, 0);
}
Oops, that was a Copy/Paste error when I was placing it on the forums. Let me be more specific about the error. I thought the syntax looked correct for C# but I’m getting an error on this line saying:
Expression denotes Type where Variable or Method Group is expected
and
The Left hand side of the assignment must be a variable.
This sounds relatively simple, but not familiar enough with C#.
Hi Boomcrash,
transform.position = new Vector3(0, 15, 0);
That was the important bit. I guess the C# syntax sees ‘Vector3…’ as a type, whereas ‘new Vector3(…)’ evaluates to a variable of that type.
I personally find all those 'new’s annoying. You have to use them everywhere in c# like when constructing a rect to pass into a function, eg
GUI( new Rect(0,0,1,1) …);
OMG!!! Thanks so much for pointing that out. I was about to rewrite scripts to JS as a workaround ![]()
It works as intended, happy day!!
Thanks again Trooper and bem13!