You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
1.1 KiB
40 lines
1.1 KiB
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<Car>());
|
|
}
|
|
}
|
|
}
|