RecyclableToys.cs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /****************************************************************************
  2. * Copyright 2019 Nreal Techonology Limited. All rights reserved.
  3. *
  4. * This file is part of NRSDK.
  5. *
  6. * https://www.nreal.ai/
  7. *
  8. *****************************************************************************/
  9. namespace NRKernal.Experimental.NRExamples
  10. {
  11. using UnityEngine;
  12. /// <summary> A recyclable toys. </summary>
  13. public class RecyclableToys : NRGrabbableObject
  14. {
  15. /// <summary> The origin position. </summary>
  16. private Vector3 m_OriginPos;
  17. /// <summary> The origin rot. </summary>
  18. private Quaternion m_OriginRot;
  19. /// <summary> The minimum position y coordinate. </summary>
  20. private float m_MinPositionY = -1.8f;
  21. /// <summary> Starts this object. </summary>
  22. void Start()
  23. {
  24. m_OriginPos = transform.position;
  25. m_OriginRot = transform.rotation;
  26. }
  27. /// <summary> Updates this object. </summary>
  28. void Update()
  29. {
  30. if (transform.position.y < m_MinPositionY)
  31. RecycleSelf();
  32. }
  33. /// <summary> Recycle self. </summary>
  34. private void RecycleSelf()
  35. {
  36. transform.position = m_OriginPos;
  37. transform.rotation = m_OriginRot;
  38. m_AttachedRigidbody.velocity = Vector3.zero;
  39. m_AttachedRigidbody.angularVelocity = Vector3.zero;
  40. }
  41. }
  42. }