Declaring a Class var which will GetComponent()

HI there,
I just want to make sure I have something under my belt.

I want to declare a var, which will getComponent(script) as a class var. (Class var being what I think as declared out side the first function, assessable throughout the script).

I have…

var scriptData : scriptScript = scriptAttachedObject.GetComponent(scriptScript);

and or…

var scriptData = scriptAttachedObject.GetComponent(scriptScript);

both create the error that…

…so what that means to me is that the object, script is not being recognized. It has not been defined.

This method works in a function, but how can I get it to work outside a function as a class variable.

Forgive me if my terminology is incorrect but I believe I am right.

Thanks
Ren

You can’t do it that way. But you can do it this way:

var scriptData : scriptScript;

void Start() {
    scriptData = scriptAttachedObject.GetComponent(scriptScript);
}

Assuming scriptAttachedObject is defined somehow.

Right.
ok thank you.

::)(

I’m not sure what’s going on there. Try just declaring it at class level and then initializing it in the start function. Also, make sure your statement is correct. I don’t use js much. Does this particular statement work in a function without error?

Oh, someone beat me to it.