- Home /
Is it possible to use 1 class on two different game objects and switch them alternately at runtime?
Hi, My apologies for the vague title but I wasn't sure how to write it. For this app I'm making, I'll be putting in 2 languages. I wrote a script called "NarrationPage.cs" that has two variables:
public string[] pageText;
public AudioClip[] pageSound;
This script is basically used as a container to put in the dialogues and the sounds. I put this script on two different game objects e.g. NarrationEnglish and NarrationBM; each with their own respective languages. This script is using a Singleton Pattern and I call the function in this script from another main manager script. At the moment, it can only work with one game object as in one language at one time. I thought if I have one gameobject active and the other inactive(based on the condition), I can switch the language at runtime. Is there a way to make this work, or should I write two different NarrationPage?
You will need a variable to know what is the current language, a function to change the language, i also recommend you use ScriptableObjects to save each language data in a asset, and use only a single GameObject switching the current ScriptableObject.
Thank you. This is the first time I've heard this sorcery called ScriptableObject. Will look into it.