TargetDistanceSlider.cs 652 B

123456789101112131415161718
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. public class TargetDistanceSlider : MonoBehaviour
  6. {
  7. public void onSlider()
  8. {
  9. float distance = this.GetComponent<Slider>().value * 70f;
  10. GameObject targetBodyNode = GameObject.Find("GameArea/TargetObject");
  11. if (targetBodyNode == null) return;
  12. TargetBody target = targetBodyNode.GetComponentInChildren<TargetBody>();
  13. target.SetDistance(distance);
  14. Text text = this.transform.Find("Text").GetComponent<Text>();
  15. text.text = "箭靶距离 - " + distance.ToString("#0.00") + "米";
  16. }
  17. }