is there a way to get a random component? Meaning, I have a system which will raycast hit a btn of tag pause. upon hitting it will ask for its component, but, the components vary from btn to btn. Is there a way to see what components are attached then choose?
You should use class inheritance so it doesn’t matter.
class Button extends MonoBehaviour {
function Push() {
Debug.Log("You pushed a Button");
}
}
...
class DeathButton extends Button {
function Push() {
Debug.Log("You pushed DEATH");
}
}
If you attach a DeathButton to objectA, then:
var button : Button = objectA.GetComponent(Button);
button.Push();
Will print ‘You pushed DEATH’.
no. that is a specific, all be it scary component. thanks. Its ok, I know the component, i just needed to put an if in since it would be one of three objects. each with there own.