using System.Threading.Tasks; using UnityEngine; public class CarControl : MonoBehaviour { private float speed = 5; public bool canRotate = false; // Start is called before the first frame update void Start() { 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().Length; i++) { for (int j = 0; j < testcar.GetComponentsInChildren()[i].materials.Length; j++) { testcar.GetComponentsInChildren()[i].materials[j].SetFloat("_Distance", a); } } await Task.Delay(50); } if (Bootstrap.UIMgr != null) Bootstrap.UIMgr.ShowPanel(this, E_UI_Layer.System, (p) => { p.Init($"您的爱车已入场!",3); Bootstrap.Instance.eventCenter.EventTrigger(Enum_EventType.ChangeChildrenMat,false); Bootstrap.Instance.eventCenter.EventTrigger(Enum_EventType.AudioPlay, $"车辆入场"); 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); } } }