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.

39 lines
1.2 KiB

  1. namespace VRTK.Examples.Archery
  2. {
  3. using UnityEngine;
  4. public class ArrowNotch : MonoBehaviour
  5. {
  6. private GameObject arrow;
  7. private VRTK_InteractableObject obj;
  8. private void Start()
  9. {
  10. arrow = transform.Find("Arrow").gameObject;
  11. obj = GetComponent<VRTK_InteractableObject>();
  12. }
  13. private void OnTriggerEnter(Collider collider)
  14. {
  15. var handle = collider.GetComponentInParent<BowHandle>();
  16. if (handle != null && obj != null && handle.aim.IsHeld() && obj.IsGrabbed())
  17. {
  18. handle.nockSide = collider.transform;
  19. arrow.transform.SetParent(handle.arrowNockingPoint);
  20. CopyNotchToArrow();
  21. collider.GetComponentInParent<BowAim>().SetArrow(arrow);
  22. Destroy(gameObject);
  23. }
  24. }
  25. private void CopyNotchToArrow()
  26. {
  27. GameObject notchCopy = Instantiate(gameObject, transform.position, transform.rotation) as GameObject;
  28. notchCopy.name = name;
  29. arrow.GetComponent<Arrow>().SetArrowHolder(notchCopy);
  30. arrow.GetComponent<Arrow>().OnNock();
  31. }
  32. }
  33. }