- Home /
What's wrong with this simple script?
Right now i get the this error when pressing the play button:
-Assets/Movement new.js(2,14): UCE0001: ';' expected. Insert a semicolon at the end.
This is the Script:
using UnityEngine.Transform;
function Start () {
}
function Update () {
if (Input.GetButton("Forward"))
Transform.Translate(Vector3.forward);
}
when i put a ; after the identifier "using" like Unity tells me to. (Which would make no sence.) I get the following errors:
-Assets/Movement new.js(9,27): BCE0020: An instance of type 'UnityEngine.Transform' is required to access non static member 'Translate'.
-Assets/Movement new.js(1,1): BCE0005: Unknown identifier: 'using'.
-Assets/Movement new.js(1,20): BCE0034: Expressions in statements must only be executed for their side-effects.
So i can't figure out whats wrong, i just started scripting, and i believe everything in there is right. (Although i am appearantly horribly wrong. If there is something wrong with it please tell me, it's kinda really bugging me.
EDIT: thanks everyone, it's now fixed, but now i have another problem, i added some stuff, and now it gives me an error about a non-existant line, how can i solve this?
Updated script:
import UnityEngine.Transform;
function Start () {
}
function Update () { if (Input.GetButton("Move Forwards")) transform.Translate(Vector3.forward);
{
if (Input.GetButton("Move Backwards"))
transform.Translate(-Vector3.forward);
}
Accompanied By the error: Assets/Movement new.js(16,1): BCE0044: expecting }, found ''.
That's what i find weird, since there is no sixteenth line. This happend to my previous scripts as well, making them all unuseable.
EDIT2: Nevermind, i managed to fix it.
Answer by PAEvenson · Sep 04, 2013 at 11:57 AM
change this:
Transform.Translate(Vector3.forward);
to:
transform.Translate(Vector3.forward);
Also 'using' is a c# keyword. It's 'import' in US isn't it?
you do not need to import UnityEngine.Transform. You can remove that line completely.
Unity says that i in fact need the UnityEngine.Trasfor.translate
and it said using in the Official tutorial on the Unity site, so i went with that.
'Transform' refers to the Transform class itself, whereas 'transform' refers to the instance of said class attached to the gameobject. Confusing, I know, but the casing is consistent throughout Unity.
Your answer
Follow this Question
Related Questions
variables within variables? 2 Answers
Animator Controller 0 Answers
Junior Programming Pathway scaling a cube 2 Answers
Issue with animation and gravity. 1 Answer
Help with script please, boss and destroyed message 1 Answer