48 lines
1.1 KiB
C#
48 lines
1.1 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
public class Trigger_Station2 : MonoBehaviour
|
|
{
|
|
public GameObject obj1;
|
|
|
|
|
|
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 < 100)
|
|
Current_Battery += consumption * Time.deltaTime;
|
|
txt_battery.text = Current_Battery.ToString("f2") + "%";
|
|
}
|
|
|
|
private void Start()
|
|
{
|
|
obj1.SetActive(false);
|
|
|
|
}
|
|
// Start is called before the first frame update
|
|
private void OnTriggerEnter(Collider other)
|
|
{
|
|
obj1.SetActive(true);
|
|
Trigger_road.dian = true;
|
|
if (bool1)
|
|
{
|
|
bool1 = false;
|
|
Current_Battery = 22.35f;
|
|
}
|
|
}
|
|
private void OnTriggerExit(Collider other)
|
|
{
|
|
obj1.SetActive(false);
|
|
Trigger_road.dian = false;
|
|
// Current_Battery = 32.15f;
|
|
}
|
|
}
|