2017-10-22 5 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 InspectorARCamera Inspector

だ、私はときのように(もタッチ入力を取得することになりますオブジェクトがタッチされると音が鳴るのですか?)

答えて

0

大丈夫、文字通り5時間以上かけて試行錯誤した後...私の主な問題は、私のオブジェクトのための私のボックスコライダーがあまりにも小さいリットル、私はそれをクリックして、なぜ時にコライダーは、単にオブジェクトをカプセル化していなかったので、したがって、それはそれを登録していなかった...

Here is my resized collider

私はthis tutorialはマウスとタッチ入力と私のために非常に有用であることがわかりました私のコードに基づいています。

私は私のARCameraにこのスクリプトを追加しました:

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); 


     } 

    } 
    } 
} 

私は私の3Dモデルにこのスクリプトを添付しました:

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

public class ObjectTest1 : MonoBehaviour { 

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

    } 
} 

あなたARCameraのオーディオリスナーコンポーネントを持っていることを確認してくださいあなたのオブジェクトのオーディオソースコンポーネント、そして最も重要なのは、オブジェクトをカプセル化して実際に動作させるためのコライダーコンポーネントです。 (私はボックスコライダーを使用しています)

関連する問題