I’m not sure if this is advanced, but i had this idea for a game controller that allows you to swap between sub-level mechanics without changing the main systems script. And I’m not sure how to go about doing this.
Example:
Main Game Mechanics Script:
Button
Light
Door
public class mainScript : MonoBehaviour
{
public MyOtherScript myOtherScript;
public Light myLight;
public GameObject myDoorObj;
float playerHealth = 10.0f;
int playerScore = 0;
string playerName = "name";
public void Start()
{
myLight.color = Color.black;
}
public void OnTriggerEnter(Collider other)
{
if (other.gameObject.tag == "button") {
myOtherScript.ButtonPressed();
}
}
public void OtherPosableControls() {
//No other controls at this time
}
}
Sub Game Mechanics Script 1 Actions: (Level 1)
Press button once only
The light turns on only
Door Opens only
public class subScriptOne : MonoBehaviour
{
public myParentScript mainScriptParent;
public void ButtonPressed() {
mainScriptParent.myLight.color = Color.white;
mainScriptParent.myDoorObj.SetActive(false);
}
}
Sub Game Mechanics Script 2 Actions: (Level 2)
Press button 2 times
Light turns on
Press button
Light blinks
Door Opens
public class subScriptTwo : MonoBehaviour
{
public myParentScript mainScriptParent;
int buttonCount;
bool blinkFastIO;
public void ButtonPressed() {
if (buttonCount == 2) {
mainScriptParent.myLight.color = Color.blue;
}
buttonCount += 1;
}
public void Update()
{
if (buttonCount >= 3)
{
if (blinkFastIO)
{
mainScriptParent.myLight.color = Color.green;
}
else
{
mainScriptParent.myLight.color = Color.red;
}
blinkFastIO = !blinkFastIO;
mainScriptParent.myDoorObj.SetActive(false);
}
}
}
Sub Game Mechanics Script 3 Actions: (Level 3)
Door Opens and closes
Pressing button will either open or close door and light
Door Opens
public class subScriptThree : MonoBehaviour
{
public myParentScript mainScriptParent;
bool myButtonState;
public void ButtonPressed() {
if (myButtonState)
{
mainScriptParent.myLight.color = Color.white;
mainScriptParent.myDoorObj.SetActive(true);
}
else {
mainScriptParent.myLight.color = Color.black;
mainScriptParent.myDoorObj.SetActive(false);
}
}
}
Idk I think it would be nice to be able to have the main script that you can swap game mechanics for each level.