using System.Collections; using System.Collections.Generic; using UnityEngine; using System; namespace BuildSystem { public class CarCollision : MonoBehaviour { public GameObject errorPre; public GameObject error=null; private void OnTriggerEnter(Collider other) { if (other.tag == "CarFw") { if (error!=null) return; error = Instantiate(errorPre, (transform.position + other.transform.position) * 0.5f, Quaternion.identity); error.transform.localEulerAngles += new Vector3(90, 0, 0); error.transform.position += new Vector3(0, 5, 0); StartCoroutine(Wait(()=> { ClearError(); },5f)); Debug.Log("撞车"); } } IEnumerator Wait(Action action,float t) { yield return new WaitForSeconds(t); action(); } void ClearError() { Destroy(error); CarController.Instance.ClearCar(transform.parent.GetComponent()); } } }