Okay… I found some basic js and tried to convert it to C#… like I do for most things due to the fact I have no official training and C# Unity tutorials are rare and normally First Person only and very, very, very, very, very, very “I got it already” basic. I keep getting this error:
Expression denotes a type', where a variable’, value' or method group’ was expected
But if I stick a new in between return and transform (ie. return new transform.TransformDirection) then that goes away and another takes it’s place(“The type or namespace name `transform’ could not be found. Are you missing a using directive or an assembly reference?”), but I think I might have broke the code… idk, I can’t figure it out. Can someone assist me and tell me just what I’m obviously doing wrong (or even point me in the right direction), cause it’s looks right to me as is. xD
Vector3 RandomForwardMovement()
{
var vx = (1 - 2 * Random.value) * offset;
var vy = (1 - 2 * Random.value) * offset;
var vz = 1.0;
return transform.TransformDirection (Vector3 (vx, vy, vz));
}
I really don’t wanna use js… it’s just so… -shakes head- speed limited… mostly cause I know I’d mess it up to the point it would run the scripts at the speed of snail… darn you js for not being very picky and allowing me to do (mostly) whatever!
You should find this very, very, very interesting:
http://forum.unity3d.com/threads/175410-Finally-an-interactive-tutorial-series-that-WILL-teach-you-C-for-Unity3D
First, that should be new Vector 3 for line 6 to get rid of the first error.
Second, I’ll (most likely) need to see when/how you call RandomForwardMovement.
Third, the original code would be helpful 
Also, I rather not look up the Docs, but just in case… Are you using TransformDirection right, parameter-wise?
public Vector3 RandomForwardMovement(){
float vx = (-1 * Random.value) * offset;
float vy = (-1 * Random.value) * offset;
float vz = 1.0;
return transform.TransformDirection (new Vector3 (vx, vy, vz));
}
It’s best to always code your types (eg. using float in my example vs var in yours), also the error was probably coming from the “return” line since you didn’t tell the compiler to create a “new” vector 3.
EDIT:
@MDragon - Yeah he’s using it right (had to look at the docs myself). You put in a local Vector 3 and it returns a global Vector 3
When you just type “Vector3” you are referring to the abstract type, but when you type “new Vector3(x,y,z)” you are actually creating a concrete Vector3 object. TransformDirection needs an actual object so you want to type:
return transform.TransformDirection (new Vector3 (vx, vy, vz));
You should also use “float” instead of “var”. If you know what type your variables are, you should explicitly state it. The compiler can figure it out from the context, but it’s not necessary in this case and only makes the code harder to read. There are specific places where you need to use “var” (check the C# Reference), but usually you want to explicitly type your variables.
Hmm… Don’t know how I missed that, but by seeing how I just edited a bunch of little errors in the post I just made this late at night (for me), that makes sense.
Thanks Slidaekar for correcting that.
So I was right on needing the ‘new,’ I was just plopping it in the wrong place. x.x That’s what I get for working in the middle of the night. xD Thanks everyone.
No problem, and best of luck on your venture! Feel free to come back and ask questions any time.