VR4RoboticArm2/VR4RoboticArm/Assets/Scripts/InstantiateObjects.cs
IonutMocanu d7aba243a2 Main
2025-09-08 11:04:02 +03:00

56 lines
1.8 KiB
C#

using System.Collections;
using System.Collections.Generic;
using NUnit.Framework;
using UnityEngine;
public class InstantiateObjects : MonoBehaviour
{
[SerializeField] private GameObject obiect; //obiectul care va intra pe linia de asamblare
[SerializeField] private List<Cloth> clothObjects = new List<Cloth>();
[SerializeField] private float timeToWaitForDestroyColliders; // numarul de secunde pentru a astepta ca colliderul obiectului sa fie scos din lista de vectori ai hainelor;
[SerializeField] private float timeToSpawn; //intervalul de timp intre generarea obiectelor
//folosim coroutine pentru a genera obiectele
IEnumerator Start()
{
StartCoroutine("GenerateObjects");
yield return new WaitForSeconds(1.0f);
print("Incepe generarea de obiecte");
}
private IEnumerator GenerateObjects()
{
GameObject obiectGenerat = Instantiate(obiect, transform.position, Quaternion.identity);
CapsuleCollider cp = obiectGenerat.GetComponent<CapsuleCollider>();
foreach (Cloth cloth in clothObjects)
{
cloth.capsuleColliders = new CapsuleCollider[] {cp};
//cloth.capsuleColliders.SetValue(cp, cloth.capsuleColliders.Length-1);
}
print(clothObjects[0].capsuleColliders.Length);
yield return new WaitForSeconds(timeToSpawn);
print("Au trecut "+timeToSpawn+" secunde");
StartCoroutine(DeleteColliders(obiectGenerat));
}
private IEnumerator DeleteColliders(GameObject obiectGenerat)
{
foreach (Cloth cloth in clothObjects)
{
cloth.capsuleColliders = new CapsuleCollider[0];
//cloth.capsuleColliders.ReValue(obiectGenerat.GetComponent<CapsuleCollider>(), cloth.capsuleColliders.Length + 1);
}
yield return null;
StartCoroutine(GenerateObjects());
}
}