154 lines
4.1 KiB
C#
154 lines
4.1 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
public class Trigger_Station : MonoBehaviour
|
|
{
|
|
/// <summary>
|
|
/// 无感充电
|
|
/// </summary>
|
|
public Transform NoFeelingCD;
|
|
/// <summary>
|
|
/// 无感充电特效
|
|
/// </summary>
|
|
private Transform NoFeelingEffect;
|
|
/// <summary>
|
|
/// 正常充电特效
|
|
/// </summary>
|
|
//public Transform NorMalEffect;
|
|
|
|
///解决 无感充电 重置问题
|
|
bool isFFirstTime = true;
|
|
|
|
/// <summary>
|
|
/// 解决无感充电UI显示问题
|
|
/// </summary>
|
|
public static bool istrue = true;
|
|
|
|
public GameObject obj1;
|
|
|
|
/// <summary>
|
|
/// 充完电速度问题
|
|
/// </summary>
|
|
bool istrigger = true;
|
|
public GameObject SpeedText1;
|
|
public GameObject SpeedText2;
|
|
public GameObject SpeedText3;
|
|
public GameObject SpeedText4;
|
|
|
|
|
|
private float Max_Battery = 100f;//最大电量
|
|
private float Min_Battery = 0f;//最大电量
|
|
private float Current_Battery = 20f;//最大电量
|
|
private float consumption = 0.1f;//消耗电量速度
|
|
public Text txt_battery;
|
|
|
|
bool bool1 = true;
|
|
private void Update()
|
|
{
|
|
|
|
if (Current_Battery < 99.3F)
|
|
Current_Battery += consumption * Time.deltaTime;
|
|
txt_battery.text = Current_Battery.ToString("f2") + "%";
|
|
}
|
|
|
|
private void Start()
|
|
{
|
|
//obj1.SetActive(false);
|
|
|
|
NoFeelingCD.GetChild(1).GetComponent<Button>().onClick.AddListener(XuanZeFangshi1);//无感支付
|
|
NoFeelingCD.GetChild(2).GetComponent<Button>().onClick.AddListener(XuanZeFangshi2);//直流充电
|
|
//NoFeelingEffect=NoFeelingCD.GetChild(2);
|
|
|
|
|
|
}
|
|
// Start is called before the first frame update
|
|
private void OnTriggerEnter(Collider other)
|
|
{
|
|
//obj1.SetActive(true);
|
|
// Trigger_road.dian = true;
|
|
if (bool1)
|
|
{
|
|
Current_Battery = 12.15f;
|
|
bool1 = false;
|
|
}
|
|
//transform.parent.parent.SendMessage("Audio_CDZ_station");
|
|
|
|
//踩到外面的才可以重新计算
|
|
if (istrue == true)
|
|
{
|
|
istrue = false;
|
|
NoFeelingCD.gameObject.SetActive(true);//无感充电
|
|
NoFeelingCD.GetChild(0).gameObject.SetActive(true);
|
|
NoFeelingCD.GetChild(1).gameObject.SetActive(true);
|
|
NoFeelingCD.GetChild(2).gameObject.SetActive(true);
|
|
//速度问题
|
|
SpeedText1.SetActive(false);
|
|
SpeedText2.SetActive(true);
|
|
}
|
|
|
|
//if (istrigger)
|
|
//{
|
|
// SpeedText1.SetActive(false);
|
|
// SpeedText2.SetActive(true);
|
|
// istrigger = false;
|
|
//}
|
|
}
|
|
private void OnTriggerExit(Collider other)
|
|
{
|
|
//obj1.SetActive(false);
|
|
Trigger_road.dian = false;
|
|
NoFeelingCD.Find("无感充电提示语").gameObject.SetActive(false);
|
|
}
|
|
private void OnTriggerStay(Collider other)
|
|
{
|
|
if (Input.GetKeyDown(KeyCode.JoystickButton10))
|
|
{
|
|
|
|
XuanZeFangshi1();//开始无感充电
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 选择充电方式 无感充电
|
|
/// </summary>
|
|
void XuanZeFangshi1()
|
|
{
|
|
//无感充电
|
|
NoFeelingCD.Find("无感充电提示语").gameObject.SetActive(true);
|
|
NoFeelingCD.GetChild(0).gameObject.SetActive(false );
|
|
NoFeelingCD.GetChild(1).gameObject.SetActive(false);
|
|
NoFeelingCD.GetChild(2) .gameObject.SetActive(false);
|
|
Trigger_road.dian = false;
|
|
|
|
if (!isFFirstTime)
|
|
{
|
|
print("无感充电动画重置完成");
|
|
NoFeelingCD.Find("无感充电提示语").GetComponent<Animator>().SetTrigger("isTrigger");
|
|
}
|
|
else
|
|
{
|
|
isFFirstTime = false;
|
|
}
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 选择充电方式 直流充电
|
|
/// </summary>
|
|
void XuanZeFangshi2()
|
|
{
|
|
//直流充电
|
|
|
|
//NorMalEffect.gameObject.SetActive(true);
|
|
|
|
}
|
|
void FinishCD()
|
|
{
|
|
print("结束充电");
|
|
NoFeelingCD.gameObject.SetActive(false);
|
|
//NorMalEffect.gameObject.SetActive(false);
|
|
}
|
|
|
|
}
|