private IEnumerator SpawnLoad() { _towerData.ResetTower(); Rigidbody[] bodies = new Rigidbody[_dataLoaded.jengas.Length]; for (int i = 0; i < _dataLoaded.jengas.Length; ++i) { JengaPieceData piece = _dataLoaded.jengas[i]; if (Math.Abs(piece.position.x) < .001f && Math.Abs(piece.position.y) < .001f && Math.Abs(piece.position.z) < .001f ) { continue; } GameObject instance = _piecePool.Instantiate(); Transform transformPiece = instance.transform; instance.transform.parent = _tower.transform; transformPiece.localPosition = piece.position; transformPiece.localRotation = Quaternion.Euler(piece.rotation); transformPiece.localScale = piece.scale; pieceHeight = piece.scale.y + 0.05f; pieceWidth = piece.scale.x + 0.05f; Material material = pieceMaterials[i % 2]; instance.GetComponent <PieceOriginalMaterial>().originalMaterial = material; instance.GetComponent <MeshRenderer>().material = material; bodies[i] = instance.GetComponent <Rigidbody>(); bodies[i].isKinematic = true; _towerData.AddPiece(instance); } yield return(new WaitForSeconds(2f)); foreach (Rigidbody body in bodies) { body.isKinematic = false; } _towerData.towerAlreadyBuilt = true; }