first commit
This commit is contained in:
43
Assets/Scripts/ScaleZone.cs
Normal file
43
Assets/Scripts/ScaleZone.cs
Normal file
@@ -0,0 +1,43 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user