- Home /
BCE0044 and UCE0001 Error Need Help!!!
#pragma strict
var MyCube = function MyCube() {
var positionX : int;
var positionY : int;
var positionZ : int;
};
function Update () {
Transform.position.X = MyCube.positionX;
Transform.position.Y = MyCube.positionY;
Transform.position.Z = MyCube.positionZ;
if(Input.getKey("q")) {
MyCube.positionX = MyCube.positionX + 1;
}
if(Input.getKey("a")) {
MyCube.positionX = MyCube.positionX - 1;
}
if(Input.getKey("w")) {
MyCube.positionY = MyCube.positionY + 1;
}
if(Input.getKey("s")) {
MyCube.positionY = MyCube.positionY - 1;
}
if(Input.getKey("e")) {
MyCube.positionZ = MyCube.positionZ + 1;
}
if(Input.getKey("d")) {
MyCube.positionZ = MyCube.positionZ - 1;
}
}
I can't seem to find the error in my code
The semicolon 7 is supposed to be there because it is a variable with a function inside. This code is in javascript.
Format code properly with 10101 button
Your opening declaraction of var mycube = function mycube() doesn't look like legal syntax to me, but I use C#
Answer by robertbu · Feb 20, 2014 at 07:07 AM
This may be what you are looking for. In addition to the issue @getyour411 points out where you are using a function where you should be using a class, you have these issues:
You want to use 'transform' not 'Transform'. 'Transform' with an upper case 'T' is the class. Lower case 'transform' is the instance on this game object.
transform.position x,y, and z values are lower case
getKey should be 'GetKey'.
pragma strict
class MyCubeClass extends System.Object { var positionX : int; var positionY : int; var positionZ : int; };
var MyCube = new MyCubeClass();
function Update () { transform.position.x = MyCube.positionX; transform.position.y = MyCube.positionY; transform.position.z = MyCube.positionZ;
if(Input.GetKey("q")) { MyCube.positionX = MyCube.positionX + 1; } if(Input.GetKey("a")) { MyCube.positionX = MyCube.positionX - 1; } if(Input.GetKey("w")) { MyCube.positionY = MyCube.positionY + 1; } if(Input.GetKey("s")) { MyCube.positionY = MyCube.positionY - 1; } if(Input.GetKey("e")) { MyCube.positionZ = MyCube.positionZ + 1; } if(Input.GetKey("d")) { MyCube.positionZ = MyCube.positionZ - 1; } }
Note this code expects the initial values of 'MyCube' to be set in the inspector.