Hello everyone, and I hope you can help me sort this out.
So I’m trying to make an augmented reality remote for Arduino. I bought the Bluetooth asset from Tech Tweaking, and everything worked fine until then.
When I added the Vuforia part, the asset no longer worked. It had a button that said “Open devices” and listed the Bluetooth devices that were available. Yet when I add the AR part, it no longer does it. Any idea on why this happens and how to solve it? I leave the codes I’m using for further details. Thanks in advance for the help.
This one is for detecting the touch on the AR cube
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class camera : MonoBehaviour {
// Update is called once per frame
void Update () {
int touchCorrection = 1;
RaycastHit hit = new RaycastHit();
for (int i = 0; i+touchCorrection < Input.touchCount; ++i) {
if (Input.GetTouch(i).phase.Equals(TouchPhase.Began)) {
// Construct a ray from the current touch coordinates
Ray ray = Camera.main.ScreenPointToRay(Input.GetTouch(i).position);
if (Physics.Raycast(ray, out hit)) {
hit.transform.gameObject.SendMessage("OnMouseDown");
}
}
}
}
}
This one is for detecting changing the object color and changing the text that is supposed to be sent to the Arduino.
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using UnityEngine.UI;
public class red : MonoBehaviour {
public Text dataToSend;
bool isHighlighted = false;
Material originalMaterial;
Material redMaterial;
MeshRenderer meshRenderer;
GameObject baseObject;
string obj_name;
// Use this for initialization
void Start () {
obj_name = this.gameObject.name;
baseObject = GameObject.Find( obj_name );
meshRenderer = baseObject.GetComponent<MeshRenderer>();
originalMaterial = meshRenderer.material;
Color red = new Color(255.0f,0.0f,0.0f,0.5f);
//Color red = new Color(255.0f,0.0f,0.0f, 0.5f);
redMaterial = new Material(Shader.Find("Transparent/Parallax Specular"));
redMaterial.color = red;
}
// Update is called once per frame
void Update () {
}
void OnMouseDown(){
Debug.Log("OMD "+obj_name);
isHighlighted = !isHighlighted;
if( isHighlighted == true ){
HighlightRed();
dataToSend.text = "<U>";
}
if ( isHighlighted==false ){
RemoveHighlight();
dataToSend.text = "<u>";
}
}
void HighlightRed(){
meshRenderer.material = redMaterial;
Debug.Log("IT SHOULD BE RED");
}
void RemoveHighlight(){
meshRenderer.material = originalMaterial;
}
}
And this last one for activating a button from within the script that sends the text via bluetooth.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
public class fake_click : MonoBehaviour {
[SerializeField] GameObject[] buttons;
int buttonIndex = 0;
void OnMouseDown () {
ExecuteEvents.Execute<IPointerClickHandler>(buttons[buttonIndex] , new PointerEventData(EventSystem.current),ExecuteEvents.pointerClickHandler);
}
}