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().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().constraints = RigidbodyConstraints.FreezeAll; } } void FixedUpdate() { if (!firstNucleon) gameObject.GetComponent().AddForce((transform.parent.parent.transform.position - transform.position).normalized * 500 * Time.smoothDeltaTime); } IEnumerator freezePos() { yield return new WaitForSeconds(3f); gameObject.GetComponent().constraints = RigidbodyConstraints.FreezeAll; } }