Hi all,
I’m trying to get my scripts to be pragma strict, all going fine bar this little bit of code. I can’t seem to figure out the correct syntax for it. I get errors saying the types aren’t covertible.
Anyone know what the correct method?
function OnDrawGizmos () {
var childrenTransforms : Transform[];
childrenTransforms = gameObject.GetComponentsInChildren ( Transform ) as Transform;
}
var childrenTransforms = gameObject.GetComponentsInChildren.<Transform>();
–Eric
Magic, thanks 
Any chance you could elaborate on the difference between (Transform) and .() ?
Bit of a newbie to this, would be good to know for future reference 
Actually I think I understand - the () just returns them as an array of components (i.e. Component[ ] ), where the .<>() returns it as an array of those component types (i.e. Transform[ ] ) ?
Yes, using generics–() rather than (Transform)–casts to the specified type, instead of Component[ ].
–Eric
That makes sense.
So throughout my scripts where I’ve got nonsense like…
var thisRigidbody : Rigidbody;
thisRigidbody = GetComponent ( Rigidbody ) as Rigidbody;
…to get around pragma strict, I could just use…
var thisRigidbody : Rigidbody;
thisRigidbody = GetComponent.<Rigidbody> ();
…and save myself some messy code?
Yes, though personally I’d further shorten it to
var thisRigidbody = GetComponent.<Rigidbody>();
–Eric
Yeah, I was just compressing that down for readability. Usually I’d be defining a private var or something that’s been declared outside of the function that the GetComponent’s in.
Thanks, dude, that’s cleared this up for me a lot 
Bumping this for more #pragma strict help.
When writing a custom inspector for my script, it’s throwing errors at me along the lines of;
The code looks like this;
@CustomEditor (worldObject)
class worldObjectEditor extends Editor {
function OnInspectorGUI () {
target.objectName = EditorGUILayout.TextField("Object name: ", target.objectName);
}
}
The script with worldObject.js on it simply has this in it;
var objectName : String = "Default object";
Since the editor assigns the target variable itself… I’m not sure what I can do about it.
Any ways around this?
Huh, it works if I do;
@CustomEditor (worldObject)
class worldObjectEditor extends Editor {
var targetWO : worldObject;
function OnInspectorGUI () {
targetWO = GameObject.Find( target.name ).GetComponent.< worldObject > ();
targetWO.objectName = EditorGUILayout.TextField("Object name: ", targetWO.objectName);
}
}
but that seems awkward and hacky to me. I’m not sure it’s the correct way to go about it.
edit;
Think I’ve got it. Seems the easy way to do it is;
@CustomEditor (worldObject)
class worldObjectEditor extends Editor {
var targetWO : worldObject;
function OnInspectorGUI () {
targetWO = target;
targetWO.objectName = EditorGUILayout.TextField("Object name: ", targetWO.objectName);
}
}
it’s not complaining at least.
You would cast Object to the appropriate type…instead of “target.objectName”, use “(target as WorldObject).objectName”.
–Eric