#pragma strict
function Start () {
int a;
}
function Update () {
for(a=1;a<20;a++)
{
System.out.println(a);
}
}
This code gives me this error
Assets/NewBehaviourScript.js(4,4): UCE0001: ‘;’ expected. Insert a semicolon at the end.
Why?
#pragma strict
function Start () {
int a;
}
function Update () {
for(a=1;a<20;a++)
{
System.out.println(a);
}
}
This code gives me this error
Assets/NewBehaviourScript.js(4,4): UCE0001: ‘;’ expected. Insert a semicolon at the end.
Why?
It’s not Java, it’s JavaScript (technically UnityScript… meh)
In JavaScript, you define variables like so:
var a : int;
I learning JavaScript in Netbeans. Does Netbeans use thier own method to define a variables?
Or is it because I / we are writing in UnityScript there defines variables on a difrent method?
Even the Web JavaScript is not able to declare variables by writing the type of the variable. You still need the var keyword as DanielQuick already told you
UnityScript is able to declare the type of the variable, but you still need the var keyword:
#pragma strict
var a : int;
function Update () {
for(a = 1; a < 20; a++)
{
System.out.println(a);
}
}
or:
#pragma strict
function Update () {
for(var : int a = 1; a < 20; a++)
{
System.out.println(a);
}
}
or this:
#pragma strict
function Update () {
for(var a = 1; a < 20; a++)
{
System.out.println(a);
}
}
(the last variant is only possible when you initialize the variable, just declaring is not enough)
Fixed it for you.
Another topic you should look into is variable scope; a variable declared in the Start function is not accessible from the Update function.
Okay Thanks.
Right now I have an object.
I want it to only move in Y-axis
And I am using right know
rigidbody.AddForce(transform.up * amount);
And I only want it to stay in Y-Axis, is there something I can do there make my object moveable in only Y-axis, but not changine the X and Z position
On the rigidbody you can set the restraints to freeze position on X and Z axes via the inspector.
Thanks it were working with freeze,
My code look like this:
function Start () {
}
function Update () {
rigidbody.constraints = RigidbodyConstraints.FreezeRotationX | RigidbodyConstraints.FreezeRotationZ;
var amount : int;
amount = 500;
if(transform.position.y<8)
if (Input.GetKeyDown ("space"))
rigidbody.AddForce (Vector3.up * 500);
}
But when i times Vector3.up with 500 is it possible that amount could be there, since i could not type amount in because it said “No match found”.
And instead of 500, I want to right in in “unity” at the script list instead of type in the code, if you can follow me