forked from nope5166/AtomCraft-2.28
44 lines
1.3 KiB
C#
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;
|
|
}
|
|
}
|