44 lines
913 B
C#
44 lines
913 B
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class ScaleZone : MonoBehaviour
|
|
{
|
|
private List<Rigidbody> _objects = new List<Rigidbody>();
|
|
|
|
private void OnTriggerEnter(Collider other)
|
|
{
|
|
Rigidbody rb = other.GetComponentInParent<Rigidbody>();
|
|
if (rb == null) return;
|
|
|
|
if (!rb.CompareTag("Target")) return;
|
|
|
|
if (!_objects.Contains(rb))
|
|
_objects.Add(rb);
|
|
}
|
|
|
|
private void OnTriggerExit(Collider other)
|
|
{
|
|
Rigidbody rb = other.GetComponentInParent<Rigidbody>();
|
|
if (rb == null) return;
|
|
|
|
_objects.Remove(rb);
|
|
}
|
|
|
|
public float TotalWeight
|
|
{
|
|
get
|
|
{
|
|
float total = 0f;
|
|
|
|
foreach (var rb in _objects)
|
|
{
|
|
if (rb != null)
|
|
total += rb.mass;
|
|
}
|
|
|
|
return total;
|
|
}
|
|
}
|
|
}
|