Hello Guys,
I got a little Problem: I would like to safe a script (that is a component of a gameobject) into a variable in an other script.
For example:
GameObject XYZ got 2 scripts like
ScriptA{
public Component MyScriptXZY;
public void MyFunction{
MyScriptXYZ.StuffShouldHappen();
}
}
ScriptB{
public void StuffShouldHappen{
//le totally awesome stuff
}
}
I can simply drag my ScriptB of the Gameobject into the Componentvariable of ScriptA, but I can’t do anything with the variable. I got no access to he mehtods of ScriptB.
How can I adress the methods of Scrip?
My mainproblem is, thats why I want to do it like that, is that the script within the Component-Variable might be different, depending on the gameobject.
But since I want to adress the method with on line like Component.MyMethod() instead of an anoying
if(HasComponent"ScriptX")stuff()
if(HasComponent"ScriptY")stuff()
…
Is there a way to do it the way I need it?
Thanks for any help!