Assignment for RMIT Mixed Reality in 2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

32 lines
936 B

namespace VRTK.Examples
{
using UnityEngine;
public class Gun : VRTK_InteractableObject
{
private GameObject bullet;
private float bulletSpeed = 1000f;
private float bulletLife = 5f;
public override void StartUsing(VRTK_InteractUse usingObject)
{
base.StartUsing(usingObject);
FireBullet();
}
protected void Start()
{
bullet = transform.Find("Bullet").gameObject;
bullet.SetActive(false);
}
private void FireBullet()
{
GameObject bulletClone = Instantiate(bullet, bullet.transform.position, bullet.transform.rotation) as GameObject;
bulletClone.SetActive(true);
Rigidbody rb = bulletClone.GetComponent<Rigidbody>();
rb.AddForce(-bullet.transform.forward * bulletSpeed);
Destroy(bulletClone, bulletLife);
}
}
}