Init
This commit is contained in:
49
Assets/ThirdParty/DestroyIt/Scripts/Runtime/Behaviors/ActivateDestructibles.cs
vendored
Normal file
49
Assets/ThirdParty/DestroyIt/Scripts/Runtime/Behaviors/ActivateDestructibles.cs
vendored
Normal file
@@ -0,0 +1,49 @@
|
||||
using UnityEngine;
|
||||
// ReSharper disable IdentifierTypo
|
||||
|
||||
namespace DestroyIt
|
||||
{
|
||||
public class ActivateDestructibles : MonoBehaviour
|
||||
{
|
||||
private DestructionManager _destructionManager;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
_destructionManager = DestructionManager.Instance;
|
||||
if (_destructionManager == null)
|
||||
{
|
||||
Debug.LogError("DestructionManager could not be found or created in the scene. Removing script.");
|
||||
Destroy(this);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnTriggerEnter(Collider other)
|
||||
{
|
||||
// Ignore Player objects
|
||||
if (other.gameObject.CompareTag("Player")) return;
|
||||
|
||||
Destructible destructible = other.gameObject.GetComponentInParent<Destructible>();
|
||||
if (destructible == null) return;
|
||||
|
||||
if (destructible.isTerrainTree && _destructionManager.destructibleTreesStayDeactivated) return;
|
||||
|
||||
if (!destructible.enabled)
|
||||
destructible.enabled = true;
|
||||
}
|
||||
|
||||
private void OnTriggerExit(Collider other)
|
||||
{
|
||||
// Ignore Player objects
|
||||
if (other.gameObject.CompareTag("Player")) return;
|
||||
|
||||
Destructible destructible = other.gameObject.GetComponentInParent<Destructible>();
|
||||
if (destructible == null) return;
|
||||
|
||||
if (destructible.enabled && !destructible.isTerrainTree && _destructionManager.autoDeactivateDestructibles) // deactivate non-terrain trees
|
||||
destructible.shouldDeactivate = true;
|
||||
else if (destructible.enabled && destructible.isTerrainTree && _destructionManager.autoDeactivateDestructibleTerrainObjects) // deactivate terrain trees
|
||||
destructible.shouldDeactivate = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user