赞
踩
VR拆装(HTC vive Pro开发)——6、一些脚本的分享(三)
namespace VRTK.Examples { using UnityEngine; using VRTK; using UnityEngine.UI; public class Knowledge : VRTK_InteractableObject { public GameObject[] Obj; //定义数组Obj[];存储所有零件 public Text now_text; //定义文本框所显示的文本 public Text[] the_text; //定义文本数组the_text[],用来存储所有文本内容 public AudioSource music; //音频 public AudioClip[] FuChuAudio; //定义音频数组FuChuAudio[],存储所有音频 public int num = 0; //定义自变量num,且初始值为0 /// <summary> /// 手柄在物体里面一直待用 /// </summary> /// <param name="e"></param> public override void OnInteractableObjectTouched(InteractableObjectEventArgs e) { base.OnInteractableObjectTouched(e); // Debug.Log("物体被手柄触摸了" + gameObject.name); /*for (num = 0; num < 99; num++) { if (Obj[num].name == gameObject.name) { now_text.text = the_text[num].text; //Debug.Log("匹配成功" + num); } }*/ } /// <summary> /// 开始触摸 /// </summary> /// <param name="currentTouchingObject"></param> public override void StartTouching(GameObject currentTouchingObject) //手柄与物体碰撞触发事件方法 { base.StartTouching(currentTouchingObject); //检测如果碰撞到某个零件 for (num = 0; num < 99; num++) { if (Obj[num].name == gameObject.name) //判断拿起的是哪个零件 { now_text.text = the_text[num].text; //显示该零件的文本内容 music.clip = FuChuAudio[num]; music.Play(); //播放该零件的音频 //Debug.Log("匹配成功" + num); } } } /// <summary> /// 结束触摸 /// </summary> /// <param name="previousTouchingObject"></param> public override void StopTouching(GameObject previousTouchingObject) { base.StopTouching(previousTouchingObject); } } }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。