I am trying to convert this part of a script from C# to unityscript.
PART OF IT:
public bool CanAttack
{
get
{
return shootCooldown <= 0f;
}
}
I don’t know much of C#, I was used of seeing ; in the end, or of function which started with public void …
But this has none of it.
And I am not sure how to do it, is this the right way? :
public var CanAttack : boolean;
{
get
{
return shootCooldown <= 0f;
}
This may be a little un-orthodox, but the simplest way I found to transfer variables from any script to any other script, without depending on compile order or any of that mess, are empty GameObjects (for bool variables).
For example (JS):
private var MyBooleEmptyGameObject : GameObject;
private var BoolInThisScript = false;
function Start ()
{
MyBooleEmptyGameObject = GameObject.Find ("/Variables/MyBooleEmptyGameObject");
if (MyBooleEmptyGameObject.transform.localPosition.y > 0.5)
{
BoolInThisScript = true;
}
else
{
BoolInThisScript = false;
}
}
I usually keep all my Empty GameObject variables under another Empty GameObject called “Variables”, to keep things neat. I also use the 0.5 Y position as the threshold between true and false, as sometimes in Unity GameObjects MAY change their position by 0.000000001
So using > 0.5 or < 0.5 is the safe bet.
The same process can be done with string, int or float.