VR4RoboticArm2/VR4RoboticArm/Assets/Scripts/InstantiateObjects1.cs
2025-09-13 11:51:52 +03:00

89 lines
2.4 KiB
C#

using NUnit.Framework;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using static UnityEditor.U2D.ScriptablePacker;
public class InstantiateObjects1 : MonoBehaviour
{
[SerializeField] private GameObject obiect; //obiectul care va intra pe linia de asamblare
[SerializeField] private float timeToSpawn; //intervalul de timp intre generarea obiectelor
[SerializeField] private GameObject placa;
[SerializeField] private float rotateAngle;
[SerializeField] private float duration;
private Quaternion startRotation;
private Quaternion endRotation;
//folosim coroutine pentru a genera obiectele
IEnumerator Start()
{
startRotation = transform.rotation;
StartCoroutine("GenerateObjects");
yield return new WaitForSeconds(1.0f);
print("Incepe generarea de obiecte");
}
private IEnumerator GenerateObjects()
{
endRotation = startRotation * Quaternion.Euler(0f,rotateAngle,0f);
float elapsed = 0f;
while (elapsed < duration)
{
placa.transform.rotation = Quaternion.Slerp(
startRotation,
endRotation,
elapsed / duration
);
elapsed += Time.deltaTime;
yield return null;
}
placa.transform.rotation = endRotation;
yield return new WaitForSeconds(0.2f);
GameObject obiectGenerat = Instantiate(obiect, transform.position, Quaternion.identity);
CapsuleCollider cp = obiectGenerat.GetComponent<CapsuleCollider>();
yield return new WaitForSeconds(0.2f);
elapsed = 0f;
while (elapsed < duration)
{
placa.transform.rotation = Quaternion.Slerp(
endRotation,
startRotation,
elapsed / duration
);
elapsed += Time.deltaTime;
yield return null;
}
placa.transform.rotation = startRotation; // corecție final
yield return new WaitForSeconds(timeToSpawn);
Debug.Log("Au trecut " + timeToSpawn + " secunde");
StartCoroutine(DeleteColliders(obiectGenerat));
}
private IEnumerator DeleteColliders(GameObject obiectGenerat)
{
Debug.Log("S-a sters");
yield return new WaitForSeconds(1f);
StartCoroutine(GenerateObjects());
}
}