ParentToGrandparentOnStart.cs 1.1 KB

1234567891011121314151617181920212223242526272829
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. /// <summary>
  5. /// Causes the attached transform to change its parent to its parent's parent on Start.
  6. /// This is done so you can conveniently keep this object in the same position as its parent when
  7. /// working in the editor, but it'll stop inheriting changes to that transform at runtime.
  8. /// Done for the MR calibration transform controls (arrows/rings) to hold the "limit" indicators,
  9. /// which should not move when the user clicks and drags the control.
  10. /// </summary>
  11. public class ParentToGrandparentOnStart : MonoBehaviour
  12. {
  13. // Use this for initialization
  14. void Start ()
  15. {
  16. if(transform.parent != null && transform.parent.parent != null)
  17. {
  18. transform.SetParent(transform.parent.parent);
  19. }
  20. else
  21. {
  22. Debug.LogWarning("Could not set parent to transform's parent because either this transform or its " +
  23. "current parent do not have a parent."); //Try saying THAT five times fast.
  24. }
  25. }
  26. }