Files
ScienceLab.WeightAndMass/Assets/Scripts/ScaleTest/WeighingManager.cs
2026-04-07 03:14:32 +03:00

43 lines
1.0 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class WeighingManager : MonoBehaviour
{
[SerializeField] private DraggableObject[] _balls;
[SerializeField] private float _normalMass = 1f;
[SerializeField] private float _heavyMass = 1.5f;
private void Start()
{
AssignMasses();
}
public void AssignMasses()
{
foreach (var ball in _balls)
{
ball.mass = _normalMass;
ball.isHeavy = false;
ball.GetComponent<Rigidbody>().mass = _normalMass;
}
int heavyIndex = Random.Range(0, _balls.Length);
_balls[heavyIndex].mass = _heavyMass;
_balls[heavyIndex].isHeavy = true;
_balls[heavyIndex].GetComponent<Rigidbody>().mass = _heavyMass;
}
public void ResetAllBalls()
{
foreach (var ball in _balls)
ball.ResetToStart();
}
public void FullRestart()
{
foreach (var ball in _balls)
ball.ResetToStart();
AssignMasses();
}
}