2024-03-19 17:43:48 +01:00

44 lines
1.3 KiB
C#

using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class Nucleon : MonoBehaviour
{
private float maxRandomOffset = 0.03f;
public bool firstNucleon = false;
void Start()
{
if (!firstNucleon)
{
if (transform.parent.parent.gameObject.GetComponent<Atom>().freezeNucleusMovementAfter5Seconds)
{
StartCoroutine(freezePos());
}
// Add randomization to the starting position within a sphere around the initial position
Vector3 randomOffset = Random.insideUnitSphere * maxRandomOffset; // Define maxRandomOffset as a public float variable
transform.position += randomOffset;
}
else
{
transform.localPosition = new Vector3(0f, 0f, 0f);
gameObject.GetComponent<Rigidbody>().constraints = RigidbodyConstraints.FreezeAll;
}
}
void FixedUpdate()
{
if (!firstNucleon)
gameObject.GetComponent<Rigidbody>().AddForce((transform.parent.parent.transform.position - transform.position).normalized * 500 * Time.smoothDeltaTime);
}
IEnumerator freezePos()
{
yield return new WaitForSeconds(3f);
gameObject.GetComponent<Rigidbody>().constraints = RigidbodyConstraints.FreezeAll;
}
}