2017-10-22 1 views
1

안녕하세요, 3D 개체를 클릭하여 소리를 출력하려고했지만 아무 일도 일어나지 않았습니다.AR 개체를 클릭 할 때 오디오 출력

나는 나의 ARCamera에이 스크립트를 첨부했습니다 :

using System.Collections; 
using System.Collections.Generic; 
using UnityEngine; 

public class CameraTest1 : MonoBehaviour { 

// Use this for initialization 
void Start() { 

} 

// Update is called once per frame 
void Update() { 

    if (Input.GetMouseButton(0) || Input.GetMouseButtonDown(0)) 
    { 
     Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); 
     RaycastHit hit; 
     if (Physics.Raycast(ray, out hit)) 
     { 
      if (hit.collider.tag == "clickableObject") 
      { 
       GameObject obj = GameObject.FindGameObjectWithTag("clickableObject"); 
       obj.GetComponent<AudioSource>().Play(); 
      } 
     } 
    } 
} 
} 

가 여기 내 Object Inspector 이 일단 ARCamera Inspector

의 난 때와 같이 (도 터치 입력을 얻기 위해 조사해야하는 위치 구현 얻는다 객체가 소리를 만졌습니까?)

답변

0

문자 그대로 5 시간 이상 동안 시행 착오를 한 후에 ... 내 주된 문제는 내 객체에 대한 내 상자 콜 리더가 너무 희박하다는 것이 었습니다. 내가 그것을 클릭 할 때 입자 가속기가 단순히 객체를 캡슐화되지 않았기 때문에 난 따라서 이유는

Here is my resized collider

...를 등록하지 않은 나는 this tutorial 마우스 매우 유용하다는 것을 발견하고 터치 입력 및 I 내 코드를 기반으로.

using System.Collections; 
using System.Collections.Generic; 
using UnityEngine; 

public class ObjectTest1 : MonoBehaviour { 

void touchBegan() { 
    this.gameObject.GetComponent<AudioSource>().Play(); 

    } 
} 

당신이 당신의 ARCamera에 오디오 수신기 구성 요소가 있는지 확인 : 내 3D 모델에이 스크립트를 첨부했습니다

using System.Collections; 
using System.Collections.Generic; 
using UnityEngine; 

public class CameraTest1 : MonoBehaviour 
{ 

private List<GameObject> touchList = new List<GameObject>(); 
private GameObject[] touchPrev; 
private RaycastHit hit; 

void Update() 
{ 


    if (Input.GetMouseButton(0) || Input.GetMouseButtonDown(0)) 
    { 
     touchPrev = new GameObject[touchList.Count]; 
     touchList.CopyTo(touchPrev); 
     touchList.Clear(); 

     Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); 

     if (Physics.Raycast(ray, out hit)) 
     { 
      Debug.Log("test"); 

      GameObject recipient = hit.transform.gameObject; 
      touchList.Add(recipient); 

      recipient.SendMessage("touchBegan", hit.point, SendMessageOptions.DontRequireReceiver); 


     } 

    } 
    } 
} 

:

나는 나의 ARCamera에이 스크립트를 추가했습니다 및 귀하의 개체에 오디오 소스 구성 요소와 가장 중요한 것은 실제로 작동하도록 귀하의 개체를 캡슐 collider 구성 요소! (상자 콜리더를 사용하고 있습니다)

관련 문제