batteryDiagnosis/Assets/Scripts/CarControl.cs

60 lines
1.7 KiB
C#

using System.Threading.Tasks;
using UnityEngine;
public class CarControl : MonoBehaviour
{
private float speed = 7;
public bool canRotate = false;
// Start is called before the first frame update
void Start()
{
if (Bootstrap.Instance != null) Bootstrap.Instance.eventCenter.AddEventListener(Enum_EventType.ChangeCarSwitch, ChangeCarSwitch);
}
// Update is called once per frame
void Update()
{
if (canRotate)
{
transform.Rotate(transform.forward, speed * Time.deltaTime, Space.World);
}
}
public GameObject testcar;
public async void ChangeCarSwitch()
{
if (testcar == null) return;
await Task.Delay(2000);
float a = 4f;
while (a <= 11)
{
a += 0.1f;
for (int i = 0; i < testcar.GetComponentsInChildren<MeshRenderer>().Length; i++)
{
for (int j = 0; j < testcar.GetComponentsInChildren<MeshRenderer>()[i].materials.Length; j++)
{
testcar.GetComponentsInChildren<MeshRenderer>()[i].materials[j].SetFloat("_Distance", a);
}
}
await Task.Delay(50);
}
Bootstrap.Instance.eventCenter.EventTrigger(Enum_EventType.ChangeChildrenMat, false);
Bootstrap.Instance.eventCenter.EventTrigger(Enum_EventType.StepSwitching);
canRotate = !canRotate;
}
public async void StepSwitching()
{
await Task.Delay(50);
}
private void OnDisable()
{
if (Bootstrap.Instance != null)
{
Bootstrap.Instance.eventCenter.RemoveEventListener(Enum_EventType.ChangeCarSwitch, ChangeCarSwitch);
}
}
}