TargetDistanceSlider.cs 677 B

12345678910111213141516171819202122232425
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. public class TargetDistanceSlider : MonoBehaviour
  6. {
  7. GameObject target;
  8. Text text;
  9. void Start()
  10. {
  11. target = GameObject.Find("GameArea/010");
  12. text = this.transform.Find("Text").GetComponent<Text>();
  13. }
  14. public void onSlider()
  15. {
  16. float value = this.GetComponent<Slider>().value;
  17. Vector3 v3 = target.transform.localPosition;
  18. v3.x = 7.718f + (-17.12f - 7.718f) * value;
  19. target.transform.localPosition = v3;
  20. text.text = "箭靶距离 - " + (10f + value * 60f).ToString("#0.00") + "米";
  21. }
  22. }