- Home /
; expected insert semicolon at the end
var speed; - 3.0;
var rotateSpeed; - 3.0;
function Update ()
{
var controller : CharacterController; - GetComponent(CharacterController);
// Rotate around y - axis
transform.Rotate(0, Input.GetAxis ("Horizontal") * rotateSpeed, 0);
// Move forward / backward
var forward; - transform * TransformDirection(Vector3.forward);
var curSpeed; speed Input.GetAxis; ("Vertical");
controller.SimpleMove(forward * curSpeed);
}
@script RequireComponent(CharacterController)
Both Monodevelop and Unity say that i need a semicolon straight after the Input.GetAxis but i already have one there. I am only 12 and a beginner programmer. Any help appreciated it is also in javascript if that is any help
Please use the 101010 button to convert your code into a form that is more readable.
would this fix the script completely?? Thanks for the help
screenhog that only created more issues now it says unexpected token at the two lines that i put a colon on
Is it alright if I rewrite this script in C# for you? I don't really know UnityScript as well as C#.
What is this supposed to do? $$anonymous$$ove the character? You can just use the normal fps controller or something
No, that won't fix the entire script. To be honest, now that I see your script in a readable form, I'm not quite sure what you've written or what you're trying to do.
Answer by Screenhog · Sep 26, 2012 at 10:32 PM
You have many extra semicolons, and generally seem to be mixing up colons and semicolons.
For instance, speed and rotateSpeed in your first lines should have a = instead of a ; after them:
var speed = -3.0;
var rotateSpeed = -3.0;
That still won't work...it needs to be
var speed = -3.0;
var rotateSpeed = -3.0;
Duh... sorry about that, don't know what I was thinking.
@Screenhog: Ins$$anonymous$$d of posting that comment (or at least in addition) you should have fixed your answer by editing it ;)
I've fixed it for you, so i don't have to downvote it ;)
Answer by CaioRosisca · Sep 26, 2012 at 11:49 PM
Try that
var speed : float = -3.0;
var rotateSpeed : float = - 3.0;
function Update ()
{
var controller : CharacterController = GetComponent(CharacterController);//I think it should be ("CharacterController") //with ""
// Rotate around y - axis
transform.Rotate(0, Input.GetAxis ("Horizontal") * rotateSpeed, 0);
// Move forward / backward
var forward = transform.TransformDirection(Vector3.forward);
var curSpeed = speed * Input.GetAxis("Vertical");
controller.SimpleMove(forward * curSpeed);
}
@script RequireComponent(CharacterController)
Caio it still isnt working it says i need a semicolon after speed = but when i put one there it creates more problems
What does the "var curSpeed = speed Input.GetAxis("Vertical");" line mean? What was it supposed to do?
Perhaps you wanted "speed * Input.GetAxis("Vertical");"
@Screenhog is right, my bad. it should be: var curSpeed = speed*Input.GetAxis("Vertical");
the line "var curSpeed = speed Input.GetAxis("Vertical");" sets the variable curSpeed to the input the engine receives from axis "vertical"(default W and S keys), the value is a range between -1 and 1..then it times speed to get a bigger number..then it's usedto move the player on that speed
Don't suggest to use GetComponent with a string. You will lose the type of the returned component. Since the variable is explicitly typed in this case it would work, but in general use the Type and not string version.
Btw: You can edit any post you make here. I'll fix it for you
edit
I also fixed the "var forward" line. You can't multiply a component with a function ;) The function TransformDirection is actually a part of transform, so you need a dot "."
ps: The code in the question is actually a totally messed up version of the sample in Simple$$anonymous$$ove. I'm not sure how he managed to get this sample that wrong (since you can just copy it). $$anonymous$$aybe he's just a spammer begging for karma? :D