67 lines
2.3 KiB
C#
67 lines
2.3 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()
|
|
{
|
|
|
|
List<CapsuleCollider> allCapsuleColliders = new();
|
|
|
|
GameObject obiectGenerat = Instantiate(obiect, transform.position, Quaternion.identity);
|
|
|
|
foreach(Transform child in obiectGenerat.transform)
|
|
{
|
|
foreach(CapsuleCollider col in child.GetComponentsInChildren<CapsuleCollider>())
|
|
{
|
|
Debug.Log("Hai ca se paote");
|
|
allCapsuleColliders.Add(col);
|
|
}
|
|
}
|
|
|
|
//CapsuleCollider cp = obiectGenerat.GetComponent<CapsuleCollider>();
|
|
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<CapsuleCollider>(), cloth.capsuleColliders.Length + 1);
|
|
}
|
|
Debug.Log("S-a sters");
|
|
yield return null;
|
|
StartCoroutine(GenerateObjects());
|
|
}
|
|
|
|
}
|
|
|