70 lines
1.6 KiB
C#
70 lines
1.6 KiB
C#
using DG.Tweening;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class StopValveGai : MonoBehaviour
|
|
{
|
|
[SerializeField] int mix;
|
|
[SerializeField] int max;
|
|
[SerializeField] float initPos;
|
|
public float Sum;
|
|
public int currentValue = 0;
|
|
public Transform trans;
|
|
[SerializeField] float x;
|
|
[SerializeField] int ZhuanSum;//要旋转一次的角度
|
|
[SerializeField] bool isok = false;
|
|
[SerializeField] Button btn;
|
|
// Start is called before the first frame update
|
|
void Start()
|
|
{
|
|
btn.onClick.AddListener(() =>
|
|
{
|
|
if (!isok)
|
|
{
|
|
if (Sum < max)
|
|
{
|
|
Sum += ZhuanSum;
|
|
currentValue--;
|
|
}
|
|
else
|
|
{
|
|
isok = true;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (Sum > mix)
|
|
{
|
|
|
|
Sum -= ZhuanSum;
|
|
currentValue++;
|
|
}
|
|
else
|
|
{
|
|
isok = false;
|
|
}
|
|
|
|
}
|
|
|
|
Deng(Sum);
|
|
});
|
|
}
|
|
void Deng(float angle)
|
|
{
|
|
float z = Mathf.Clamp(angle, mix, max);
|
|
btn.transform.localEulerAngles = new Vector3(0, 0, z);
|
|
Sum = z;
|
|
if (transform.name.Equals("万用表"))
|
|
{
|
|
trans.DOLocalRotate(new Vector3(x, 0, ~(int)z), 0.01f);
|
|
}
|
|
else
|
|
{
|
|
trans.DOLocalRotate(new Vector3(x, ~(int)z, 0), 0.01f);
|
|
}
|
|
//Debug.Log(Mathf.Clamp(~(int)z, mix, max));
|
|
}
|
|
}
|