186 lines
5.6 KiB
C#
186 lines
5.6 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Threading.Tasks;
|
|
using Script;
|
|
using UnityEngine;
|
|
|
|
public class AccidentManager : MonoBehaviour
|
|
{
|
|
public GameObject uis;
|
|
private string triggerName;
|
|
|
|
public GameObject[] baotai;
|
|
public CarGearControl carGearControl;
|
|
|
|
public Animation zuiwei;
|
|
public Animator diandongcheren;
|
|
|
|
public Mesh mesh;
|
|
public MeshFilter meshFilter;
|
|
public void Close()
|
|
{
|
|
for (int i = 0; i < uis.transform.Find("UI").childCount; i++)
|
|
{
|
|
uis.transform.Find("UI").GetChild(i).gameObject.SetActive(false);
|
|
}
|
|
|
|
for (int i = 0; i < baotai.Length; i++)
|
|
{
|
|
baotai[i].SetActive(false);
|
|
}
|
|
|
|
zuiwei.gameObject.SetActive(false);
|
|
diandongcheren.gameObject.SetActive(false);
|
|
|
|
|
|
|
|
meshFilter.mesh = mesh;
|
|
}
|
|
|
|
|
|
public async Task Tr(Transform other, bool b = false)
|
|
{
|
|
triggerName = other.name;
|
|
|
|
|
|
if (other.transform.tag == "People")
|
|
{ await Task.Delay(TimeSpan.FromSeconds(2));
|
|
Close();
|
|
uis.SetActive(true);
|
|
uis.transform.Find("UI").Find("撞倒行人").gameObject.SetActive(true);
|
|
}
|
|
else if (other.name == "Box_Collider")
|
|
{ await Task.Delay(TimeSpan.FromSeconds(2));
|
|
Close();
|
|
uis.SetActive(true);
|
|
uis.transform.Find("UI").Find("汽车追尾").gameObject.SetActive(true);
|
|
}
|
|
else if (other.name == "爆胎")
|
|
{
|
|
for (int i = 0; i < baotai.Length; i++)
|
|
{
|
|
baotai[i].SetActive(true);
|
|
}
|
|
await Task.Delay(TimeSpan.FromSeconds(2));
|
|
Close();
|
|
uis.SetActive(true);
|
|
uis.transform.Find("UI").Find("爆胎").gameObject.SetActive(true);
|
|
|
|
|
|
}
|
|
else if (other.name == "礼让行人")
|
|
{
|
|
if (b)
|
|
{
|
|
await Task.Delay(TimeSpan.FromSeconds(2));
|
|
Close();
|
|
uis.SetActive(true);
|
|
uis.transform.Find("UI").Find("礼让行人").gameObject.SetActive(true);
|
|
carGearControl.mingdi = false;
|
|
}
|
|
else
|
|
{
|
|
carGearControl.mingdi = true;
|
|
}
|
|
}
|
|
else if (other.name == "隧道汽车追尾")
|
|
{
|
|
StartCoroutine(PlayAnimation());
|
|
}
|
|
else if (other.transform.tag == "diandongche")
|
|
{
|
|
StartCoroutine(diandongche());
|
|
}
|
|
else if (other.name == "刹车失灵")
|
|
{ await Task.Delay(TimeSpan.FromSeconds(2));
|
|
Close();
|
|
uis.SetActive(true);
|
|
uis.transform.Find("UI").Find("刹车失灵").gameObject.SetActive(true);
|
|
}
|
|
}
|
|
IEnumerator dengdai()
|
|
{
|
|
zuiwei.gameObject.SetActive(true);
|
|
|
|
zuiwei.Play("donghua");
|
|
// 等待动画播放完毕
|
|
yield return new WaitForSeconds(zuiwei["donghua"].length);
|
|
Close();
|
|
uis.SetActive(true);
|
|
uis.transform.Find("UI").Find("汽车追尾").gameObject.SetActive(true);
|
|
// 在这里编写动画播放完之后的代码
|
|
// 例如: Debug.Log("动画播放完成");
|
|
}
|
|
IEnumerator PlayAnimation()
|
|
{
|
|
zuiwei.gameObject.SetActive(true);
|
|
|
|
zuiwei.Play("donghua");
|
|
// 等待动画播放完毕
|
|
yield return new WaitForSeconds(zuiwei["donghua"].length);
|
|
Close();
|
|
uis.SetActive(true);
|
|
uis.transform.Find("UI").Find("汽车追尾").gameObject.SetActive(true);
|
|
// 在这里编写动画播放完之后的代码
|
|
// 例如: Debug.Log("动画播放完成");
|
|
}
|
|
|
|
IEnumerator diandongche()
|
|
{
|
|
diandongcheren.gameObject.SetActive(true);
|
|
|
|
diandongcheren.Play("diandongchedonghua");
|
|
// 等待动画播放完毕
|
|
yield return new WaitForSeconds(diandongcheren.GetCurrentAnimatorStateInfo(0).length);
|
|
Close();
|
|
uis.SetActive(true);
|
|
uis.transform.Find("UI").Find("电动车穿行").gameObject.SetActive(true);
|
|
// 在这里编写动画播放完之后的代码
|
|
// 例如: Debug.Log("动画播放完成");
|
|
}
|
|
|
|
private void OnTriggerEnter(Collider other)
|
|
{
|
|
Tr(other.transform);
|
|
|
|
// switch (other.name)
|
|
// {
|
|
// case "刹车失灵":
|
|
// uis.transform.Find("刹车失灵").gameObject.SetActive(true);
|
|
// break;
|
|
// case "礼让行人":
|
|
// uis.transform.Find("礼让行人").gameObject.SetActive(true);
|
|
// break;
|
|
// case "汽车追尾":
|
|
// uis.transform.Find("汽车追尾").gameObject.SetActive(true);
|
|
// break;
|
|
// case "电动车穿行":
|
|
// uis.transform.Find("电动车穿行").gameObject.SetActive(true);
|
|
// break;
|
|
// case "撞倒行人":
|
|
// uis.transform.Find("撞倒行人").gameObject.SetActive(true);
|
|
// break;
|
|
// case "爆胎":
|
|
// uis.transform.Find("爆胎").gameObject.SetActive(true);
|
|
// break;
|
|
// }
|
|
}
|
|
|
|
private void OnTriggerExit(Collider other)
|
|
{
|
|
// for (int i = 0; i < uis.transform.childCount; i++)
|
|
// {
|
|
// uis.transform.GetChild(i).gameObject.SetActive(false);
|
|
// }
|
|
//
|
|
// for (int i = 0; i < baotai.Length; i++)
|
|
// {
|
|
// baotai[i].SetActive(false);
|
|
// }
|
|
//
|
|
//
|
|
//
|
|
// uis.SetActive(false);
|
|
}
|
|
} |