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.

117 lines
2.8 KiB

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public enum ShouFeiType
{
,
,
}
public class ShouFeiGan : MonoBehaviour
{
private Animator animator;
public GameObject efffect;
public ShouFeiType ShouFeiType = ShouFeiType.;
public GameObject shoufeiTipParent;
public Text shoufeiTip;
public bool isOpenEnd=true;
private void Start()
{
efffect.SetActive(false);
animator = this.GetComponent<Animator>();
}
private void OnTriggerEnter(Collider other)
{
if (other.gameObject.tag == "Car")
{
Car car = null;
car = other.gameObject.GetComponent<Car>();
car.driveStatu = CarDriveStatu.;
if (TraficManager.Instance.startJiFei)
{
efffect.SetActive(true);
}
if (ShouFeiType == ShouFeiType.)
{
TraficManager.Instance.AddShoufeiInfo(car.CarType, car.CarIDCard, 0);
if (TraficManager.Instance.startJiFei)
{
shoufeiTip.text = "开始计费";
}
}
else
{
int ran = UnityEngine.Random.Range(40, 200);
TraficManager.Instance.AddShoufeiInfo(car.CarType, car.CarIDCard, ran);
if (TraficManager.Instance.startJiFei)
{
shoufeiTip.text = "收费:" + ran + "元";
}
}
StartCoroutine(TimeAction(0.5f, () => {
if (car != null)
{
car.driveStatu = CarDriveStatu.;
efffect.SetActive(false);
}
}));
StartCoroutine(TimeAni("Open", 1f));
}
}
private void OnTriggerExit(Collider other)
{
if (other.gameObject.tag == "Car")
{
isOpenEnd = false;
StartCoroutine(TimeAni("Close", 0.01f));
StartCoroutine(TimeAction(1.5f,()=> {
if (other.GetComponent<Car>() != null)
{
other.GetComponent<Car>().driveStatu = CarDriveStatu.;
isOpenEnd = true;
}
}));
}
}
IEnumerator TimeAction(float time ,Action action)
{
yield return new WaitForSeconds(time);
action();
}
IEnumerator TimeAni(string AniName,float time)
{
yield return new WaitForSeconds(time);
animator.CrossFade(AniName, 0.1f);
}
}