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 clothObjects = new List(); [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() { List allCapsuleColliders = new(); GameObject obiectGenerat = Instantiate(obiect, transform.position, Quaternion.identity); foreach(Transform child in obiectGenerat.transform) { foreach(CapsuleCollider col in child.GetComponentsInChildren()) { Debug.Log("Hai ca se paote"); allCapsuleColliders.Add(col); } } //CapsuleCollider cp = obiectGenerat.GetComponent(); foreach (Cloth cloth in clothObjects) { cloth.capsuleColliders = allCapsuleColliders.ToArray(); //cloth.capsuleColliders.SetValue(cp, cloth.capsuleColliders.Length-1); } print(clothObjects[0].capsuleColliders.Length); yield return new WaitForSeconds(timeToSpawn); Debug.Log("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(), cloth.capsuleColliders.Length + 1); } Debug.Log("S-a sters"); yield return null; StartCoroutine(GenerateObjects()); } }