I was wondering if there is a better way to deal with controller scripts when you have more than one type … hmm, let me show some code…
if(isDrive){
gameDriveController = FindObjectOfType(typeof(DriveWorldController)) as DriveWorldController;
} else {
gameController = FindObjectOfType(typeof(GameController)) as GameController;
}
So here, I’ve got two game controllers. One is for driving and the other is for flying, which are in seperate scenes. From my UI script I need to contact the game controller and I use the same UI script in both sections of the game so I need to decide what type of game it is, then pick the appropriate gamecontroller.
How would you guys deal with this? Is there a cleaner way to do it without having to have two references like this?
Thanks for any ideas - I just hate the idea that I’m missing some neat way of doing it!
You could make a “Controller” class that implements the interface that is shared between your two controller classes and then have your two specific classes inherit from Controller. Inheritance: