Saomiao.cs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using SC.XR.Unity;
  5. public class Saomiao : MonoBehaviour
  6. {
  7. public SCSlider3D Slider;
  8. public BoxCollider Collider;
  9. public BoxCollider TrackCollider;
  10. public GameObject JiRou;
  11. public void OnClick()
  12. {
  13. StartCoroutine(PlayAni());
  14. JiRou.SetActive(true);
  15. }
  16. IEnumerator PlayAni()
  17. {
  18. Collider.enabled = false;
  19. TrackCollider.enabled = false;
  20. float i = 0;
  21. bool isrun = true;
  22. while (true)
  23. {
  24. yield return new WaitForSeconds(0.005f);
  25. if (isrun)
  26. {
  27. i += 0.002f;
  28. if (i >= 1)
  29. {
  30. i = 1;
  31. isrun = false;
  32. }
  33. Slider.value = i;
  34. }
  35. else
  36. {
  37. i -= 0.002f;
  38. if (i <= 0)
  39. {
  40. Slider.value = 0;
  41. Collider.enabled = true;
  42. TrackCollider.enabled = true;
  43. yield break;
  44. }
  45. Slider.value = i;
  46. }
  47. }
  48. }
  49. }