This commit is contained in:
2025-09-17 18:56:28 +08:00
commit 54c72710a5
5244 changed files with 5717609 additions and 0 deletions

View File

@@ -0,0 +1,44 @@
using UnityEngine;
namespace DestroyIt
{
/// <summary>
/// This script is used in conjunction with Object Pooling to enhance performance, in particular with mobile devices.
/// This script enables gravity on a game object's rigidbody over a small amount of time, so the physics load on the CPU is spaced out.
/// </summary>
public class EnableGravityAfter : MonoBehaviour
{
public float seconds; // seconds to wait before enabling rigidbody gravity on this game object.
private float _timeLeft;
private bool _isInitialized;
void Start()
{
_timeLeft = seconds;
_isInitialized = true;
}
void OnEnable()
{
_timeLeft = seconds;
}
void Update()
{
if (!_isInitialized) return;
if (GetComponent<Rigidbody>() == null)
{
Destroy(this);
return;
}
_timeLeft -= Time.deltaTime;
if (_timeLeft <= 0)
{
GetComponent<Rigidbody>().useGravity = true;
Destroy(this);
}
}
}
}