使用Pico实现头部跟踪
挂载的脚本如下
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class KaPian : MonoBehaviour
{
public int SceneIndex;
public AudioClip clip;
private Button btnCloseAudio;
private bool IsClickImage = true;//只能点击一次卡片
private void Start()
{
transform.GetChild(2).GetComponent<Button>().onClick.AddListener(CloseAudio);
}
public void OnClickImage()
{
if (!IsClickImage) return;
IsClickImage = false;
if (SceneIndex == 8)
{
print("播放卡片声音:" + (GongZiGangShangRen.Instance.KaPianNum + 1));
transform.GetChild(1).gameObject.SetActive(true);
GongZiGangShangRen.Instance.AudioSourceTip.clip = clip;
GongZiGangShangRen.Instance.AudioSourceTip.Play();
GongZiGangShangRen.Instance.KaPianNum++;
}
else if (SceneIndex == 9)
{
print("播放卡片声音:" + (PianBangShangRen.Instance.KaPianNum + 1));
transform.GetChild(1).gameObject.SetActive(true);
PianBangShangRen.Instance.AudioSourceTip.clip = clip;
PianBangShangRen.Instance.AudioSourceTip.Play();
PianBangShangRen.Instance.KaPianNum++;
}
else if (SceneIndex == 6)
{
print("播放卡片声音:" + (MaoDingZaRen.Instance.KaPianNum + 1));
transform.GetChild(1).gameObject.SetActive(true);
MaoDingZaRen.Instance.AudioSourceTip.clip = clip;
MaoDingZaRen.Instance.AudioSourceTip.Play();
MaoDingZaRen.Instance.KaPianNum++;
}
if (SceneIndex == 1)
{
print("播放卡片声音:" + (KuaPengCtrl.Instance.IndexCard + 1));
transform.GetChild(1).gameObject.SetActive(true);
KuaPengCtrl.Instance.AudioSourceCard.clip = clip;
KuaPengCtrl.Instance.AudioSourceCard.Play();
KuaPengCtrl.Instance.IndexCard++;
}
if (SceneIndex == 2)
{
print("播放卡片声音:" + (WeiZhangChengChe.Instance._Index + 1));
transform.GetChild(1).gameObject.SetActive(true);
WeiZhangChengChe.Instance.AudioSourceCard.clip = clip;
WeiZhangChengChe.Instance.AudioSourceCard.Play();
WeiZhangChengChe.Instance._Index++;
}
if (SceneIndex == 3)
{
print("播放卡片声音:" + (M_GunTonga.instance.index + 1));
transform.GetChild(1).gameObject.SetActive(true);
M_GunTonga.instance.audioSource.clip = clip;
M_GunTonga.instance.audioSource.Play();
M_GunTonga.instance.index++;
}
}
public void CloseAudio()
{
if (SceneIndex == 8)
{
if (GongZiGangShangRen.Instance.AudioSourceTip.isPlaying)
GongZiGangShangRen.Instance.AudioSourceTip.Stop();
}
else if (SceneIndex == 9)
{
if (PianBangShangRen.Instance.AudioSourceTip.isPlaying)
PianBangShangRen.Instance.AudioSourceTip.Stop();
}
else if (SceneIndex == 6)
{
if (MaoDingZaRen.Instance.AudioSourceTip.isPlaying)
MaoDingZaRen.Instance.AudioSourceTip.Stop();
}
else if (SceneIndex == 1)
{
if (KuaPengCtrl.Instance.AudioSourceCard.isPlaying)
KuaPengCtrl.Instance.AudioSourceCard.Stop();
}
else if (SceneIndex == 2)
{
if (WeiZhangChengChe.Instance.AudioSourceCard.isPlaying)
WeiZhangChengChe.Instance.AudioSourceCard.Stop();
}
}
}