batteryLevel
The current battery level (Read Only).
Read time 1 minuteLast updated 4 days ago
Definition
- Type: Property
- Namespace: UnityEngine
- Assembly: UnityEngine.CoreModule
public static float batteryLevel { get; }
Remarks
The current level of the battery, represented as a float between and .
01If the battery level is not available on your target platform, this property returns .
-1using UnityEngine; public class Example : MonoBehaviour { void Start() { // Check if the battery level is available if(SystemInfo.batteryLevel == -1) { Debug.Log("Battery level is not available!"); } else { // Log the current battery level Debug.Log("Battery Level: " + SystemInfo.batteryLevel); // Log a message when the battery level is low if (SystemInfo.batteryLevel > 0 && SystemInfo.batteryLevel < 0.3) { Debug.Log("Battery is low!"); } } } }
Additional Resources: SystemInfo.batteryStatus.