Search Unity

  1. Unity 2018.1 has arrived! Read about it here
    Dismiss Notice
  2. Scriptable Render Pipeline improvements, Texture Mipmap Streaming, and more! Check out what we have in store for you in the 2018.2 Beta.
    Dismiss Notice
  3. If you couldn't join the live stream, take a peek at what you missed.
    Dismiss Notice
  4. Improve your Unity skills with a certified instructor in a private, interactive classroom. Learn more.
    Dismiss Notice
  5. ARCore is out of developer preview! Read about it here.
    Dismiss Notice
  6. Magic Leap’s Lumin SDK Technical Preview for Unity lets you get started creating content for Magic Leap One™. Find more information on our blog!
    Dismiss Notice
  7. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

Please help. When I add Vuforia and scripts the bluetooth no longer works.

Discussion in 'Documentation' started by Lokdex, Jul 8, 2017.

  1. Lokdex

    Lokdex

    Joined:
    Jul 8, 2017
    Posts:
    1
    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
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using System.Collections.Generic;
    4.  
    5. public class camera : MonoBehaviour {
    6.     // Update is called once per frame
    7.     void Update () {
    8.  
    9.         int touchCorrection = 1;
    10.  
    11.         RaycastHit hit = new RaycastHit();
    12.         for (int i = 0; i+touchCorrection < Input.touchCount; ++i) {
    13.             if (Input.GetTouch(i).phase.Equals(TouchPhase.Began)) {
    14.                 // Construct a ray from the current touch coordinates
    15.                 Ray ray = Camera.main.ScreenPointToRay(Input.GetTouch(i).position);
    16.                 if (Physics.Raycast(ray, out hit)) {
    17.                     hit.transform.gameObject.SendMessage("OnMouseDown");
    18.                 }
    19.             }
    20.         }
    21.  
    22.     }
    23. }
    This one is for detecting changing the object color and changing the text that is supposed to be sent to the Arduino.
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using System.Text;
    5. using UnityEngine.UI;
    6.  
    7. public class red : MonoBehaviour {
    8.  
    9.     public Text dataToSend;
    10.     bool isHighlighted = false;
    11.     Material originalMaterial;
    12.     Material redMaterial;
    13.     MeshRenderer meshRenderer;
    14.  
    15.     GameObject baseObject;
    16.     string obj_name;
    17.     // Use this for initialization
    18.     void Start () {
    19.         obj_name        = this.gameObject.name;
    20.         baseObject      = GameObject.Find( obj_name );
    21.         meshRenderer        = baseObject.GetComponent<MeshRenderer>();
    22.         originalMaterial    = meshRenderer.material;
    23.  
    24.         Color red           = new Color(255.0f,0.0f,0.0f,0.5f);
    25.         //Color red           = new Color(255.0f,0.0f,0.0f, 0.5f);
    26.         redMaterial         = new Material(Shader.Find("Transparent/Parallax Specular"));
    27.         redMaterial.color   = red;
    28.  
    29.     }
    30.  
    31.     // Update is called once per frame
    32.     void Update () {
    33.  
    34.     }
    35.  
    36.     void OnMouseDown(){
    37.  
    38.         Debug.Log("OMD "+obj_name);
    39.         isHighlighted = !isHighlighted;
    40.  
    41.         if( isHighlighted == true ){
    42.  
    43.             HighlightRed();
    44.             dataToSend.text = "<U>";
    45.  
    46.         }
    47.         if ( isHighlighted==false ){
    48.  
    49.             RemoveHighlight();
    50.             dataToSend.text = "<u>";
    51.         }
    52.     }
    53.  
    54.     void HighlightRed(){
    55.  
    56.         meshRenderer.material = redMaterial;
    57.         Debug.Log("IT SHOULD BE RED");
    58.     }
    59.  
    60.     void RemoveHighlight(){
    61.  
    62.         meshRenderer.material = originalMaterial;
    63.     }
    64.  
    65. }
    And this last one for activating a button from within the script that sends the text via bluetooth.
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.EventSystems;
    5.  
    6. public class fake_click : MonoBehaviour {
    7.  
    8.     [SerializeField] GameObject[] buttons;
    9.     int buttonIndex = 0;
    10.  
    11.     void OnMouseDown () {
    12.         ExecuteEvents.Execute<IPointerClickHandler>(buttons[buttonIndex] , new PointerEventData(EventSystem.current),ExecuteEvents.pointerClickHandler);
    13.     }
    14. }
    15.  
     
  2. unity_iMQrZ0WPGW4x1w

    unity_iMQrZ0WPGW4x1w

    Joined:
    Oct 4, 2017
    Posts:
    1
    Did you find a solution to this? I'm having the same issue