108 lines
2.6 KiB
C#
108 lines
2.6 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class Secondarymovement : MonoBehaviour
|
|
{
|
|
public static List<Secondarymovement> secondarymovements = new List<Secondarymovement>();
|
|
public string number;//每个设备的个数
|
|
public Slider slider;
|
|
private bool isDragging = false;
|
|
private bool isp = false;
|
|
private float time1 = 3;
|
|
private float timer = 0;
|
|
private Coroutine myCoroutine;
|
|
void Awake()
|
|
{
|
|
if (GameMain.skip ==false)
|
|
{
|
|
transform.gameObject.GetComponent<Secondarymovement>().enabled = false;
|
|
}
|
|
}
|
|
void Start()
|
|
{
|
|
secondarymovements.Add(this);
|
|
number = secondarymovements.Count.ToString();
|
|
}
|
|
void Update()
|
|
{
|
|
if (Input.GetMouseButtonDown(0))
|
|
{
|
|
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
|
|
RaycastHit hit;
|
|
if (Physics.Raycast(ray, out hit))
|
|
{
|
|
Secondarymovement secondarymovement = hit.collider.GetComponent<Secondarymovement>();
|
|
if (secondarymovement&&secondarymovement.number==number)
|
|
{
|
|
Debug.Log(transform.name);
|
|
isp = true;
|
|
slider.gameObject.SetActive(true);
|
|
myCoroutine = StartCoroutine(FillProgressBar());
|
|
}
|
|
}
|
|
}
|
|
|
|
if (slider.value == 1 && myCoroutine != null)
|
|
{
|
|
StopCoroutine(myCoroutine);
|
|
myCoroutine = null;
|
|
slider.gameObject.SetActive(false);
|
|
timer = 0;
|
|
isDragging = true;
|
|
slider.value = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
IEnumerator FillProgressBar()
|
|
{
|
|
while (timer < time1 && isp)
|
|
{
|
|
timer += Time.deltaTime;
|
|
slider.value = Mathf.Lerp(slider.minValue, slider.maxValue, timer / time1);
|
|
yield return null;
|
|
}
|
|
}
|
|
void OnMouseDown()
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void OnMouseDrag()
|
|
{
|
|
if (isDragging)
|
|
{
|
|
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
|
|
RaycastHit hitInfo;
|
|
if (Physics.Raycast(ray, out hitInfo, 1000, 1 << 8))
|
|
{
|
|
isp = true;
|
|
transform.localPosition = hitInfo.point;
|
|
}
|
|
}
|
|
}
|
|
|
|
void OnMouseUp()
|
|
{
|
|
isp = false;
|
|
if (myCoroutine != null)
|
|
{
|
|
StopCoroutine(myCoroutine);
|
|
myCoroutine = null;
|
|
slider.gameObject.SetActive(false);
|
|
slider.value = 0;
|
|
timer = 0;
|
|
}
|
|
isDragging = false;
|
|
}
|
|
}
|