I have read in multiple places that
myScript.variableName
should access a variable from another script, or
myScript.function();
should call a function.
Unfortunately it does not seem to work for my scenario.
void OnTriggerEnter(Collider col) {
if (col.gameObject.tag == "Destroyable") {
col.gameObject.GetComponent("Disappear").hit = true;
}
}
My script name is Disappear and I have certain objects with the Destroyable tag, but I get an error
“‘Component’ does not contain a definition for ‘hit’ and no accessible extension method ‘hit’ accepting a first argument of type ‘Component’ could be found (are you missing a using directive or an assembly reference?)”
Is there any way to either call the disappear() function or edit a boolean variable from another script in this way?
Thanks for the help.