2017年3月29日 星期三

【03160135 吳亞芳】Week06

實作範例

按下控制器Trigger製造出藍Cube
按控制器Trigger製造出紅Cube


截圖待補

套用在empty object"Box"的程式碼Create:

using UnityEngine;
using System.Collections;
using Valve.VR;

public class Create : MonoBehaviour {
public SteamVR_TrackedObject rightController;
public GameObject redCube;
public GameObject blueCube;
public GameObject box;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
var device = SteamVR_Controller.Input ((int)rightController.index);
if (device.GetPressDown (SteamVR_Controller.ButtonMask.Trigger)) {
Instantiate (redCube, rightController.transform.position, rightController.transform.rotation, box.transform);


}
if (device.GetPress (SteamVR_Controller.ButtonMask.Trigger)) {
Instantiate (blueCube, rightController.transform.position, rightController.transform.rotation, box.transform);

}
if (device.GetPressUp (SteamVR_Controller.ButtonMask.Trigger)) {
foreach (Transform child in box.transform) {
GameObject.Destroy (child.gameObject);
}
}
}
}





-----------

撿東西的程式


截圖待補

控制器程式碼:


using UnityEngine;
using System.Collections;
using Valve.VR;
public class Touch : MonoBehaviour {
public SteamVR_TrackedObject leftController;
bool isTouch=false;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
var device = SteamVR_Controller.Input ((int)leftController.index);
if (device.GetPressDown (SteamVR_Controller.ButtonMask.Trigger)) {
isTouch = true;
}
if (device.GetPressUp (SteamVR_Controller.ButtonMask.Trigger)) {
isTouch = false;
}
}


void OnTriggerStay (Collider other){
if(other.tag=="catch" && isTouch){
other.transform.position = this.transform.position;
}
}
}


沒有留言:

張貼留言