public void SpawnDrop(Transform source) { int roll = Random.Range(1, totalWeight + 1); int cursor = 0; for (int i = 0; i < drops.Count; i++) { cursor += drops[i].weight; if (cursor >= roll) { if (drops[i].prefab != null) { GameObject obj = Pooling.Acquire(drops[i].prefab); obj.transform.position = source.position; obj.transform.rotation = source.rotation; if (keepSourceLayer) { obj.layer = source.gameObject.layer; foreach (Transform item in obj.transform) { item.gameObject.layer = source.gameObject.layer; } } } break; // correction bug: le break doit ĂȘtre fait hors du null check } } }
public void Spawn() { // var obj = Instantiate(prefab, myTransform.position, myTransform.rotation); var obj = Pooling.Acquire(prefab); obj.transform.position = myTransform.position; obj.transform.rotation = myTransform.rotation; obj.layer = gameObject.layer; foreach (Transform item in obj.transform) { item.gameObject.layer = gameObject.layer; } }