///NetworkDataController initislisieren. Es wird darauf geachtet, dass dieses Objekt nur einmal vorkommt. DontDestroyOnLoad stellt sicher, dass das GameObject auch nach Szenenwechsel zur Verfügung steht. public void InitController() { if (instance == null) { instance = this; //Erstellen der Datenspeicher Objekte und hinzufügen als Components this.gameObject.AddComponent <SensorDataStorage>(); this.gameObject.AddComponent <SensorDataStorage>(); //Verwaltung der REferenzen auf die beiden Objekte sensorDataStorage = new SensorDataStorage[2]; sensorDataStorage = this.gameObject.GetComponents <SensorDataStorage>(); //Dieses Objekt darf bei einem Szenenwechsel nicht zerstört werden. DontDestroyOnLoad(instance); } else if (this != instance) { //Sollte InstanciateController() ein weiteres Mal aufgerufen werden, das eben erstellte neue Objekt löschen //Dies verhindert mehrfache Erstellung des Objekts Destroy(this.gameObject); } }
//------------------------------------------------------------------------- // Basic Classes //------------------------------------------------------------------------- void Start() { //--- Android Input //Get the GameObject where the NetworkDatdaController is attached to networkDataControllerGameObject = GameObject.Find("NetworkDataStorageController"); //Get the script component of NetworkDataController networkDataController = networkDataControllerGameObject.GetComponent <NetworkDataController>(); //Get the Network Controller Component networkController = GameObject.Find("NetworkController").GetComponent <NetworkManagerServerController>(); //Define which kind of data from the smartphone should be used //Can also be defined at the Inspector of NetworkController GameObject in Scene init networkController.isGyroGravityRequested = true; networkController.isAcceleratorRequested = false; networkController.isCompassRequested = false; networkController.isGyroAccelerationRequested = false; networkController.isGyroRotationRequested = false; networkController.isMicrophoneRequested = false; //Get the data storage for player 01 sensorDataStoragePlayer01 = networkDataController.GetSensordataStorageForPlayer(1); //Connect gameBall to the variable gameBall = GameObject.Find("GameBall"); }