Hey peoples,
I'm an absolute beginner with Unity and Vuforia. For my Bachelor thesis, I'm working on an AR Application augmenting a physical 2D Map. For filtering the content I tried to use some 3D buttons on the side which execute different filter options.
On youtube, I found several videos to setup raycast to track model hits through touch interaction. For testing, i copied the code from the video.
I attached the script as he does in his video (https://www.youtube.com/watch?v=hi_KDpC1nzk) to my image target.
My 3D Button (Cube) is a child of it with a mesh collider on it.
Whatever I do my camera / android device does not detect any hits at all. For reasons I never get into the needed part of the function cause (Physics.Raycast(ray, out hit) never returns true...
I am absolutely clueless to what else I could do to make this work. I`ve already tried each advice I found on several forums and or videos.
This is the code I use:
using UnityEngine; using UnityEngine.Events; using UnityEngine.EventSystems;
public class buttonController : MonoBehaviour {
public AudioClip[] audioClips; public AudioSource myAudioSource; string btnName;
private void Start() { myAudioSource = GetComponent<AudioSource>(); }
private 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 "buttonPOI": myAudioSource.clip = audioClips[0]; myAudioSource.Play(); break; } } else { Debug.Log("NOTHING HAPPENED"); } } } }
I would appreciate it so much if anyone has a clue or hint.
Regards
Stephan
Hi,
Hi,
Do the 3d cubes have box coliders setup?
Thank you.
Vuforia Engine Support
Hey mcotora,
Hi,
Hi,
I would recommend to the following:
1. First make sure that the ray is being generated, add below 2 lines after the if condition:
...
First of all thanks for the
First of all thanks for the quick answers!
I will try out your advice immediatly and give you feedback what happens or doesnt happen.
I have a problem to Debug.log
I have a problem to Debug.log from my via USB connected Android device to unity console. Any advice how to do that?
Ok nvm, i got the debugging
Ok nvm, i got the debugging in Terminal running properly now.
So:
Debug.Log("Conditions for raycase have been fullfilled") is getting logged in the console which means the touch input seems to be registered.
EDIT:
EDIT:
Ok i got the things working in a complete new Project with nothing in it but the elements and scripts he used in his video.