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.

31 lines
936 B

  1. namespace VRTK.Examples
  2. {
  3. using UnityEngine;
  4. public class Gun : VRTK_InteractableObject
  5. {
  6. private GameObject bullet;
  7. private float bulletSpeed = 1000f;
  8. private float bulletLife = 5f;
  9. public override void StartUsing(VRTK_InteractUse usingObject)
  10. {
  11. base.StartUsing(usingObject);
  12. FireBullet();
  13. }
  14. protected void Start()
  15. {
  16. bullet = transform.Find("Bullet").gameObject;
  17. bullet.SetActive(false);
  18. }
  19. private void FireBullet()
  20. {
  21. GameObject bulletClone = Instantiate(bullet, bullet.transform.position, bullet.transform.rotation) as GameObject;
  22. bulletClone.SetActive(true);
  23. Rigidbody rb = bulletClone.GetComponent<Rigidbody>();
  24. rb.AddForce(-bullet.transform.forward * bulletSpeed);
  25. Destroy(bulletClone, bulletLife);
  26. }
  27. }
  28. }