/// <summary> /// Called by Unity each frame /// </summary> public void Update() { if (_pollingEnabled) { if (!VrControlsAvailable() || !InCockpit()) { _pollingEnabled = false; _waitingForVrJoystick = false; _vrJoystick = null; _vrThrottle = null; Log("Left cockpit"); } } else { if (!VrControlsAvailable() && InCockpit() && !_waitingForVrJoystick) { // Entered cockpit Log("Entered cockpit"); _waitingForVrJoystick = true; StartCoroutine(FindScripts()); return; } } // Take state from physical stick and apply to VRJoystick PollSticks(); if (!VrControlsAvailable()) { return; } SendUpdates(); }
private IEnumerator FindScripts() { while (_vrJoystick == null) { //Searches the whole game scene for the script, there should only be one so its fine _vrJoystick = FindObjectOfType <VRJoystick>(); _vrThrottle = FindObjectOfType <VRThrottle>(); if (VrControlsAvailable()) { continue; } Log("Waiting for VRJoystick..."); yield return(new WaitForSeconds(1)); } _waitingForVrJoystick = false; _pollingEnabled = true; Log("Got VRJoystick"); }
private void Awake() { lastMessage = new Message_PlaneUpdate(false, 0, 0, 0, 0, 0, 0, false, false, networkUID); lastFiringMessage = new Message_WeaponFiring(-1, networkUID); lastStoppedFiringMessage = new Message_WeaponStoppedFiring(networkUID); wheelsController = GetComponent <WheelsController>(); aeroController = GetComponent <AeroController>(); vRThrottle = gameObject.GetComponentInChildren <VRThrottle>(); if (vRThrottle == null) { Debug.Log("Cound't find throttle"); } else { vRThrottle.OnSetThrottle.AddListener(SetThrottle); } weaponManager = GetComponent <WeaponManager>(); if (weaponManager == null) { Debug.LogError("Weapon Manager was null on our vehicle"); } cmManager = GetComponentInChildren <CountermeasureManager>(); if (cmManager == null) { Debug.LogError("CountermeasureManager was null on our vehicle"); } fuelTank = GetComponent <FuelTank>(); if (fuelTank == null) { Debug.LogError("FuelTank was null on our vehicle"); } Networker.WeaponSet += WeaponSet; traverse = Traverse.Create(weaponManager); Debug.Log("Done Plane Sender"); }