- Home /
Question by
unity_5Lcw5kAD1Q9E3Q · Jul 03, 2018 at 12:13 PM ·
unity 5buttonbluetooth
How do I use android bluetooth control in unity?
I am creating an ar app that has two ar buttons If I press these button I have to send the data to my Bluetooth device please give me the suggestion.
Comment
Answer by unity_5Lcw5kAD1Q9E3Q · Jul 03, 2018 at 12:14 PM
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class soundcon : MonoBehaviour {
public AudioClip[] aClips;
public AudioSource myAudioSource;
string btnName;
// Use this for initialization
void Start () {
myAudioSource = GetComponent<AudioSource>();
}
// Update is called once per frame
void Update () {
if (Input.touchCount > 0 && Input.touches [0].phase == TouchPhase.Began) {
Ray ray = Camera.main.ScreenPointToRay (Input.GetTouch (0).position);
RaycastHit Hit;
if(Physics.Raycast(ray, out Hit)){
btnName = Hit.transform.name;
switch (btnName) {
case "myButton1":
myAudioSource.clip = aClips [0];
myAudioSource.Play ();
break;
case "myButton2":
myAudioSource.clip = aClips [1];
myAudioSource.Play ();
break;
default:
break;
}
}
}
}
}