public void TakeDamage(float damage, float vt, bool animate) { if (shieldTime <= 0) { damaged = true; live -= damage; healthSlider.value = live / initialLive; if (live <= 0f) { Die(); } else { playerAudio.PlayHurtSound(); if (animate) { backTimeCount = backTime; playerMovement.canMove = false; } } BluetoothReceiver.getInstance().viber(vt); } }
private void DiscoverDevices(Context context) { // Step 4: Scan for Bluetooth device this.Receiver = new BluetoothReceiver(this); context.RegisterReceiver(this.Receiver, new IntentFilter(BluetoothDevice.ActionFound)); this.Adapter.StartDiscovery(); }
/// Called every frame the user is still looking at a valid GameObject. This /// can be a 3D or UI element. /// /// The camera is the event camera, the target is the object the user is /// looking at, and the intersectionPosition is the intersection point of the /// ray sent from the camera on the object. public void OnGazeStay(Camera camera, GameObject targetObject, Vector3 intersectionPosition, bool isInteractive) { SetGazeTarget(intersectionPosition, isInteractive); if (targetObject.tag == "UIButton" && BluetoothReceiver.getInstance().GetBtn1Down()) { if (targetObject.name == "Text" || targetObject.name == "Image") { targetObj = targetObject.transform.parent.gameObject; } else { targetObj = targetObject; } OnClick onClick = targetObj.GetComponent <OnClick> (); if (onClick != null) { onClick.OnClickFunc(); } else { targetObj.GetComponent <Exitbutton> ().OnClickFunc(); } } }
private IEnumerator StartLevel() { if (level == 1) { fullScreenMessage.gameObject.SetActive(true); fullScreenMessage.text = "Nivell 1"; } BluetoothReceiver.getInstance().Disconnect(); float fadeTime = GameObject.Find("EventManager").GetComponent <Fading> ().BeginFade(1); yield return(new WaitForSeconds(fadeTime)); if (level == 1) //Tutorial 1 { SceneManager.LoadScene("Tutorial1"); } else if (level == 2) //Tutorial 2 { SceneManager.LoadScene("Tutorial2"); } else if (level == 3) //Tutorial 3 { SceneManager.LoadScene("Tutorial3"); } else if (level == 4) //facil { SceneManager.LoadScene("Level1"); } else if (level == 5) //dificil { SceneManager.LoadScene("Level2"); } }
void LateUpdate() { float v = BluetoothReceiver.getInstance().getYAxis(); float h = BluetoothReceiver.getInstance().getXAxis(); Move(h, v); Animating(h, v); }
private IEnumerator StartScreen() { float fadeTime = GameObject.Find("EventManager").GetComponent <Fading> ().BeginFade(1); BluetoothReceiver.getInstance().Disconnect(); yield return(new WaitForSeconds(fadeTime)); SceneManager.LoadScene("Intro"); }
// Update is called once per frame void Update() { if (HaveShield() && BluetoothReceiver.getInstance().GetBtn2Down()) { UseShield(); } if (shieldTime > 0) { shieldTime -= Time.deltaTime; shieldProgress.SendMessage("SetFillerSize", shieldTime / shieldDuration); if (shieldTime <= 0) { RemoveShield(); GameObject.Find("ShieldImage").GetComponent <Image>().color = new Color(0f, 0f, 0f, 0f); } } if (damaged) { damageImage.color = flashColour; } else { damageImage.color = Color.Lerp(damageImage.color, Color.clear, flashSpeed * Time.deltaTime); if (backTimeCount > 0f) { backTimeCount -= Time.deltaTime; Vector3 forward = head.transform.forward; Vector3 back = Quaternion.AngleAxis(head.eulerAngles.y, Vector3.up) * backDamageMovement.normalized; playerRigidbody.MovePosition(transform.position + back * backDamageSpeed * Time.deltaTime); if (backTimeCount <= 0f) { playerMovement.canMove = true; } } } damaged = false; if (poisonAlpha > 0f) { poisonImage.color = new Color(poisonImage.color.r, poisonImage.color.g, poisonImage.color.b, poisonAlpha); poisonAlpha -= poisonSpeed * Time.deltaTime; if (!poisonInvoke) { Invoke("PoisonDamage", poisonDamageTime); poisonInvoke = true; } } else { playerAudio.StopPoison(); } }
// Update is called once per frame void Update() { vrEnabled = BluetoothReceiver.getInstance().isAndroidActive(); Debug.Log("vrEnabled: " + vrEnabled + " yValue: " + Input.GetAxis("Mouse Y")); if (!vrEnabled) { angle += Input.GetAxis("Mouse X"); transform.position = player.position; transform.rotation = Quaternion.Euler(new Vector3(0f, angle * speed, 0f)); } }
private void registerReceivers() { // Register for broadcasts when a device is discovered receiver = new BluetoothReceiver(); var filter = new IntentFilter(BluetoothDevice.ActionFound); RegisterReceiver(receiver, filter); // Register for broadcasts when discovery has finished filter = new IntentFilter(BluetoothAdapter.ActionDiscoveryFinished); RegisterReceiver(receiver, filter); }
public BluetoothConnector() { this.context = Android.App.Application.Context; bluetoothManager = (BluetoothManager)context.GetSystemService(Context.BluetoothService); bluetoothAdapter = bluetoothManager.Adapter; bluetoothScanner = bluetoothManager.Adapter.BluetoothLeScanner; bluetoothReceiver = new BluetoothReceiver(devicesResults, macAddressMapping); context.RegisterReceiver(bluetoothReceiver, new IntentFilter(BluetoothDevice.ActionFound)); context.RegisterReceiver(bluetoothReceiver, new IntentFilter(BluetoothDevice.ExtraRssi)); this.scanThread = new Thread(Scan); this.scanCallback = new BluetoothScanCallback(devicesResults, macAddressMapping); }
public void GameOver(int points) { if (!gameOver) { gameOver = true; player.position = new Vector3(1000f, 1000f, 1000f); textTitle.text = "Game Over"; textPoints.text = "Puntuació: " + points; animator.SetTrigger("GameOver"); BluetoothReceiver.getInstance().Disconnect(); Invoke("GoToStartScreen", gameOverWaitTime); } }
private void Win(int points) { if (!win) { win = true; levelAudioSource.Stop(); player.position = new Vector3(1000f, 1000f, 1000f); textTitle.text = "Nivell superat!"; textPoints.text = "Puntuació: " + points; animator.SetTrigger("GameOver"); BluetoothReceiver.getInstance().Disconnect(); audioSource.Play(); Invoke("GoToStartScreen", winOverWaitTime); } }
// Use this for initialization void Start() { receiver = this; Debug.Log("Call native android code..."); AndroidJavaClass jc = new AndroidJavaClass("angelshack.com.bluetoothlibrary.ArduinoBluetoothAdapter"); Debug.Log(jc); string helloWorld = jc.CallStatic <string> ("getHelloWorld"); jo = jc.CallStatic <AndroidJavaObject> ("initialize"); Debug.Log(helloWorld); Connect(); }
private void InitializeBluetoothReceiver() { bluetoothAdapter = BluetoothAdapter.DefaultAdapter; bluetoothReceiver = new BluetoothReceiver(); bluetoothReceiver.DeviceFound += BluetoothReceiver_DeviceFound; RegisterReceiver(bluetoothReceiver, new IntentFilter(BluetoothDevice.ActionFound)); bluetoothReceiver.DiscoveryStarted += BluetoothReceiver_DiscoveryStarted; RegisterReceiver(bluetoothReceiver, new IntentFilter(BluetoothAdapter.ActionDiscoveryStarted)); bluetoothReceiver.DiscoveryFinished += BluetoothReceiver_DiscoveryFinished; RegisterReceiver(bluetoothReceiver, new IntentFilter(BluetoothAdapter.ActionDiscoveryFinished)); bluetoothReceiver.BondStateChanged += BluetoothReceiver_BondStateChanged; RegisterReceiver(bluetoothReceiver, new IntentFilter(BluetoothDevice.ActionBondStateChanged)); //rec.UUIDFetched += Rec_UUIDFetched; //RegisterReceiver(rec, new IntentFilter(BluetoothDevice.ActionUuid)); }
void Move(float h, float v) { if (canMove && (v != 0 || h != 0)) { playerAudio.PlayWalk(); Vector3 forward = head.transform.forward; Vector3 movement = Quaternion.AngleAxis(head.eulerAngles.y, Vector3.up) * new Vector3(h, 0f, v); float realSpeed = speed; //Run script if (BluetoothReceiver.getInstance().GetBtn1() && runCounter > 0) { runCounter -= Time.deltaTime * runDecreaseVelocity; realSpeed += incVelocity; run = true; playerAudio.Run(); } else { run = false; playerAudio.Walk(); } if (playerHealth.IsPoisoned()) { realSpeed /= divPoisoned; } movement = movement.normalized * realSpeed * Time.deltaTime; playerRigidbody.MovePosition(movement); playerRigidbody.MovePosition(transform.position + movement); } else { playerAudio.StopWalk(); } //Update run status if (!run && runCounter < runTime) { runCounter += Time.deltaTime; } runSlider.value = runCounter / runTime; }
// Update is called once per frame void Update() { if (BluetoothReceiver.getInstance().GetBtn3Down()) { pause = !pause; audioSource.Play(); if (pause) { Time.timeScale = 0; miniMapCamera.ToggleGeneralVision(gen.N); } else { miniMapCamera.ToggleGeneralVision(N_mini); Time.timeScale = 1; } foreach (Transform child in transform) { child.gameObject.SetActive(pause); } float alpha; if (pause) { alpha = 1f; } else { alpha = 0f; } background.color = new Color(background.color.r, background.color.g, background.color.b, alpha); elementsHUD.active = !pause; } if (BluetoothReceiver.getInstance().GetBtn2Down() && pause) { Time.timeScale = 1; StartCoroutine(StartScreen()); } }