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.

42 lines
1.0 KiB

  1. namespace VRTK.Examples
  2. {
  3. using UnityEngine;
  4. public class RealGun_SafetySwitch : VRTK_InteractableObject
  5. {
  6. public bool safetyOff = true;
  7. private float offAngle = 40f;
  8. private Vector3 fixedPosition;
  9. public override void StartUsing(VRTK_InteractUse currentUsingObject)
  10. {
  11. base.StartUsing(currentUsingObject);
  12. SetSafety(!safetyOff);
  13. }
  14. protected void Start()
  15. {
  16. fixedPosition = transform.localPosition;
  17. SetSafety(safetyOff);
  18. }
  19. protected override void Update()
  20. {
  21. base.Update();
  22. transform.localPosition = fixedPosition;
  23. if (safetyOff)
  24. {
  25. transform.localEulerAngles = new Vector3(0f, 0f, 0f);
  26. }
  27. else
  28. {
  29. transform.localEulerAngles = new Vector3(0f, offAngle, 0f);
  30. }
  31. }
  32. private void SetSafety(bool safety)
  33. {
  34. safetyOff = safety;
  35. }
  36. }
  37. }