I have a gameObject in my scene, “CharacterA.”
CharacterA has a special only-for-him script: ReactionsForCharacterA. It has a function: Panic()
Every Character has a unique-to-them script, but all of those scripts have a Panic() function.
What I want to do is to be able to reference the Panic() function from any other script.
But I have no idea how to tell Unity which script I want, via reference (not name).
I couldn’t find anyone else ever trying to do anything this silly, so Google was no help.
I tried this, but Unity won’t let it compile (no surprise):
using UnityEngine;
public class RandomOrdinaryScript: MonoBehaviour
{
//This variable is where the UniqueToA, UniqueToBe, &c scripts would go.
public Component UniqueToCharacterScript;
public void CallTheirPanic()
{
//I know what I want to ask Unity to do, but no idea how to ask it.
GetComponent<UniqueToCharacterScript>().Panic();
}
}
I tried several variants of that line.
I tried prefixing it with gameObject..
I tried turning things into strings
I tried shuffling and removing (sorts) .o.f. things.
None of them worked.
But then I thought, “This may not be possible. Let me see if anyone knows in the forums,” since a few hours of internet searches proved fruitless.
Does anyone know? Can this even be done?