2019年6月17日 星期一

AHSU week 15

和宇傑討論七巧板的程式並debug

    void OnTriggerStay(Collider col) {        
        if (device.GetPress(SteamVR_Controller.ButtonMask.Trigger) && col.tag!="desk"){               //Debug.Log ("抓起");                    // 將 physics(物理引擎) 關掉                        col.attachedRigidbody.isKinematic = true;                      // 設定controller為parent                        col.gameObject.transform.SetParent(gameObject.transform);        }              if (device.GetPressUp (SteamVR_Controller.ButtonMask.Trigger)) {                           col.gameObject.transform.SetParent (null);                       col.attachedRigidbody.isKinematic = false;                       //GameObject.Destroy (col.gameObject, 3f);                        //tossObject (col.attachedRigidbody);                }       } 
/////////////////////////////////////////////////////////////////////////////////////////////////////////    void OnCollisionStay(Collision other) {        if(other.gameObject.tag=="desk")            blue=true;    }
    void OnCollisionExit(Collision other) {        if(other.gameObject.tag=="desk")            blue=false;    }
過關條件程式碼:    void Update () {               device = SteamVR_Controller.Input ((int)trackedObj.index);             if(col_blue.blue&&col_gray.gray&&col_green.green&&col_orange.orange&&col_yellow.yellow&&col_purple.purple&&col_red.red&&col_black.black)        {            puzzover=true;            SceneManager.LoadScene ("start_menu");        }    }
/////////////////////////////////////////////////////////////////////using System.Collections;using System.Collections.Generic;using UnityEngine;
public class tranlate : MonoBehaviour{    // Start is called before the first frame update    SteamVR_TrackedObject trackedObj; SteamVR_Controller.Device device,deviceLeft,deviceRight;    public GameObject obj;    float a=0.0f,b=0.0f,c=0.0f;    Vector2 rotat=new Vector2(0.0f,0.0f);    void Start()    {        trackedObj=GetComponent<SteamVR_TrackedObject>(); a=obj.transform.position.x; b=obj.transform.position.y; c=obj.transform.position.z;    }
    // Update is called once per frame    void Update()    {        device = SteamVR_Controller.Input ((int)trackedObj.index);        if (device.GetPress (SteamVR_Controller.ButtonMask.Touchpad)){ rotat = device.GetAxis (); float angle=Vector2.Angle (new Vector2 (1, 0), rotat); if (angle > 45 && angle < 135) { if (rotat.y > 0) c+=0.02f; else c-=0.02f; } else { if (rotat.x>0) a+=0.02f; else a-=0.02f; } } obj.transform.position = (new Vector3 (a, b, c));



沒有留言:

張貼留言