2019年3月26日 星期二

week06 Jie

根據手把位置產生物件

1.結果如下


2.程式碼如下
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Valve.VR;

public class controller_ball : MonoBehaviour
{
    // Start is called before the first frame update
    public SteamVR_Action_Boolean triggerDown;//宣告Trigger所需的布林變數
    public GameObject ball;//宣告生成球體用的變數
    public GameObject controller_pos;//宣告記錄手把位址的變數
    bool state=false;
  
    void Update()
    {
        if(triggerDown.GetState(SteamVR_Input_Sources.Any))
        {
            if(state==false)
            {
                state=true;

                print("triggerDown");

                GameObject now=Instantiate(ball);//生成球體
                now.transform.position=controller_pos.transform.position;//將手把位址給予球體
            }
        }
        else
        {
            state=false;
        }
    }    
}

沒有留言:

張貼留言