mirror of
https://github.com/nothke/quality-control.git
synced 2024-11-10 12:53:43 +00:00
45 lines
838 B
C#
45 lines
838 B
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class WeightDetector : MonoBehaviour
|
|
{
|
|
HashSet<Rigidbody> enteredBodies = new HashSet<Rigidbody>();
|
|
|
|
private void OnCollisionEnter(Collision collision)
|
|
{
|
|
var rb = collision.rigidbody;
|
|
|
|
if (rb)
|
|
{
|
|
enteredBodies.Add(rb);
|
|
}
|
|
}
|
|
|
|
private void OnCollisionExit(Collision collision)
|
|
{
|
|
var rb = collision.rigidbody;
|
|
|
|
if (rb)
|
|
{
|
|
enteredBodies.Remove(rb);
|
|
}
|
|
}
|
|
|
|
public float GetTotalWeight()
|
|
{
|
|
float totalMass = 0;
|
|
foreach (var body in enteredBodies)
|
|
{
|
|
totalMass += body.mass;
|
|
}
|
|
|
|
return totalMass;
|
|
}
|
|
|
|
//private void Update()
|
|
//{
|
|
// Debug.Log(GetTotalWeight());
|
|
//}
|
|
}
|