2019年5月28日 星期二

Week15

Week15
1.今天順利的合併地圖和程式檔了(感動!!)
哇~有場景跟程式碼了
2.開始程式碼的Debug的環節惹!!
今天在老師的協助下,我們有子彈會飛了~~~
程式碼如下
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Valve.VR;
public class bullet : MonoBehaviour
{
    public SteamVR_Action_Boolean myTrigger;
    public GameObject mybullet;
    public GameObject myController;
    float x = 0;
    bool state = false;
    // Start is called before the first frame update
    void Start()
    {

    }

    // Update is called once per frame
    void Update()
    {
        if (myTrigger.GetState(SteamVR_Input_Sources.Any))
        {
            if (state == false)
            {
                state = true;

                GameObject now = Instantiate(mybullet);
                now.transform.position = myController.transform.position;
                now.transform.rotation = myController.transform.rotation;
                Rigidbody rb = now.GetComponent<Rigidbody>();
                rb.velocity = new Vector3(0, 0, 100);
                rb.velocity = transform.rotation * rb.velocity;
                Destroy(now, 15f);
            }
        }
        else
        {
            state = false;
        }

    }
}

沒有留言:

張貼留言