Can someone show me how to use transform to move an object in C#

I have just started using Unity and have hit a complete roadblock with this. I’ve been through all the beginner scripting tutorials and looked at many other tutorials, I just can’t get it to work. Unity just throws up errors even if I copy examples word for word.

Was the way transform works changed in Unity 5?

Could someone show me a simple script that would move an object to the left in C#?

Thanks in advance.

Hi,

Can you post your script?
What kind of error messages it shows?

The most common example I see in most tutorials (including the official unity ones) is something like this:

    void Update () {
        transform.Translate (Vector3(0,0,0));
}

Assets/Scripts/control.cs(13,38): error CS0119: Expression denotes a type', where a variable’, value' or method group’ was expected

Assets/Scripts/control.cs(13,27): error CS1502: The best overloaded method match for `UnityEngine.Transform.Translate(UnityEngine.Vector3)’ has some invalid arguments

Assets/Scripts/control.cs(13,27): error CS1503: Argument #1' cannot convert object’ expression to type `UnityEngine.Vector3’

The unity scripting reference contains a very niche example to changing child transforms.

You need to construct a Vector3 using the “new” keyword:

transform.Translate(new Vector3(x, y, z));

Ahhh that’s the bugger! Thanks got it working and now I can move on with my life :stuck_out_tongue: