① 安裝VR設備
② 開啟Unity
③ 開始打程式碼
③ 開始打程式碼
----------------------------------------------------------------------------------------------------------
① 安裝VR設備
② 開啟Unity
③ 開始打程式碼
1.按下手把可以顯示出Yes
►程式碼1
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Valve.VR;//自己寫的
public class mycode : MonoBehaviour
{
public SteamVR_Action_Boolean trigger;///按下按鈕出現數值
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if (trigger.GetState(SteamVR_Input_Sources.Any)
{
print("yes");///當手把按下按鈕出現yes
}
}
}
►程式碼2
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Valve.VR;//自己寫的
public class mycode : MonoBehaviour
{
public SteamVR_Action_Boolean trigger;///按下按鈕出現數值
public GameObject mySphere;
// Start is called before the first frame update
void Start()
{
}
FLOAT X=0;
// Update is called once per frame
void Update()
{
if (trigger.GetState(SteamVR_Input_Sources.Any)
{
print("yes");///當手把按下按鈕出現yes
}
GameObject now= Instantiate(mySphere);
now.transform.position =new Vector3(x,0,0);
}
}
3.按一次紅色球球可以出現在手把前面,像是在做3D圖的感覺
►最終程式碼3
using System.Collections.Generic;
using UnityEngine;
using Valve.VR;
public class myCode : MonoBehaviour
{
public GameObject myController;
public GameObject mySphere;
public SteamVR_Action_Boolean myTrigger;
// Start is called before the first frame update
void Start()
{
}
//float x = 0;
bool state = false;
// Update is called once per frame
void Update()
{
if (myTrigger.GetState(SteamVR_Input_Sources.Any)){
if (state == false){
state = true;
print("yes");
GameObject now = Instantiate(mySphere);
//now.transform.position = new Vector3(x, 0, 0);
//x++;
now.transform.position = myController.transform.position;
}
}
else{
state = false;
}
}
}
沒有留言:
張貼留言