i have a cubeController script attached to cube object and a player script attached to an empty game object.
cubeController.js:
#pragma strict
var cubeSpeed : float;
static var cubeSpeedGlobal;
function Awake()
{
cubeSpeedGlobal = cubeSpeed;
}
function Update()
{
transform.position.x -= cubeSpeed * Time.deltaTime;
}
player.js
private var cubeObj : GameObject;
function Start ()
{
cubeObj = GameObject.Find(“cube”);
}
function Update ()
{
if (Input.GetButton(“Fire1”))
{
cubeObj.transform.Rotate(Vector3(cubeController.cubeSpeedGlobal * Time.deltaTime, 0,0));
}
}
when i switch to unity i get this error:
Assets/Scripts/player.js(13,81): BCE0051: Operator ‘*’ cannot be used with a left hand side of type ‘Object’ and a right hand side of type ‘float’.
what am i doin wrong?? plz help
unity 3d 3.5.0 f1
EDIT: ignore the space between cu be.
cubeController.cubeSpeedGlobal seems to be of type object which cannot be multiplied with a float. as the error says.
static var cubeSpeedGlobal;
should probably be something like
static var cubeSpeedGlobal : float;
thats why i dont like unityscript and suggest you to use C#.
thanks for the quick reply.
am fairly new to unity and i did plan to learn C# but i found the syntax difficult so i decided to learn java first. Slowly i’ll switch to C#
Thanks again
EDIT: i forgot to mention… “float” solved the problem
the syntax is very similar imo. only declarations of functions and variables difer a bit. and when you want to learn it anyway you should start right with it. us makes things only more difficult and c# offers way more possibilities utilizing the powerfull net/mono framework.
its your decision but you must not be scared by c#. in many cases i find it easier because its more consistent. but unity allows you to mix them up to your liking.
hmmm…as soon as i get a rough idea about how scripting works inside unity, i’ll jump to C#…
Thanks.