利用unity和steamVR完成场景漫游(八) 利用VRTK实现一个产品的说明书展示①

首先我们应该来创建一个可以交互的说明书,后面再利用VIVE控制来使说明书关闭或者打开

1.创建一个主菜单,在里面添加多个按钮,按钮点击下,就会展示相应的图片说明。(在VR中,可以想象激光的照射扣扳机就是鼠标点击选取)


2.对应每个button创建相应的图片展示(可以使用Canvas或者plane)


(以下Button为关闭按钮)


因为我这个项目第四张展示有多页,多以需要添加翻页功能


3.接下来挂载脚本

需要在mainMenu下所有按钮创建点击事件,调用book_buttons中的open_book函数



4.脚本展示

book_buttons.com

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

public class book_buttons : MonoBehaviour {
	public GameObject[] objs ;
	// Use this for initialization
	void Start () {
		for (int i = 0; i < objs.Length; i++) {
			objs [i].SetActive (false);
		}
	}
	
	// Update is called once per frame
	void Update () {
		
	}
	public void open_book(int i){
		for (int a = 0; a < objs.Length; a++) {
			objs [a].SetActive (false);
		}

		objs [i].SetActive (true);
	}
}

closeButton.cs(仍需要为相应的button创建点击事件)

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

public class closebutton : MonoBehaviour {

	// Use this for initialization
	void Start () {
		
	}
	
	// Update is called once per frame
	void Update () {
		
	}
	public void close(){
		this.gameObject.SetActive (false);
	}
}

pageing.cs(拼错了= -=,记得为对应的button创建点击事件)

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


public class pageing : MonoBehaviour {


	public GameObject[] objs;


	// Use this for initialization
	void Start () {
		for (int i = 0; i < objs.Length; i++) {
			objs [i].SetActive (false);
		}
		objs [0].SetActive (true);
		objs[1].SetActive(true);
	}


	public void front(){
		for (int i = 0; i < objs.Length; i++) {
			objs [i].SetActive (false);
		}
		objs [0].SetActive (true);
		objs[1].SetActive(true);
	}
	public void second(){
		for (int i = 0; i < objs.Length; i++) {
			objs [i].SetActive (false);
		}
		objs [2].SetActive (true);
		objs[3].SetActive(true);
	}
	// Update is called once per frame
	void Update () {
		
	}
}



猜你喜欢

转载自blog.csdn.net/carotadream/article/details/80203882