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;
}
}
}
沒有留言:
張貼留言