public void Spawn() { int amtObj = 0; switch (type) { case BeachPieceType.jump: amtObj = BeachSpawnManager.Instance.jumps.Count; break; case BeachPieceType.slide: amtObj = BeachSpawnManager.Instance.slides.Count; break; case BeachPieceType.longblock: amtObj = BeachSpawnManager.Instance.longblocks.Count; break; case BeachPieceType.ramp: amtObj = BeachSpawnManager.Instance.ramps.Count; break; case BeachPieceType.shipwreck: amtObj = BeachSpawnManager.Instance.shipwrecks.Count; break; case BeachPieceType.volleyballNet: amtObj = BeachSpawnManager.Instance.volleyballNets.Count; break; } currentPiece = BeachSpawnManager.Instance.GetPiece(type, Random.Range(0, amtObj)); currentPiece.gameObject.SetActive(true); currentPiece.transform.SetParent(transform, false); }
public BeachPiece GetPiece(BeachPieceType pt, int visualIndex) { BeachPiece p = pieces.Find(x => x.type == pt && x.visualIndex == visualIndex && !x.gameObject.activeSelf); if (p == null) { GameObject go = null; if (pt == BeachPieceType.ramp) { go = ramps[visualIndex].gameObject; } else if (pt == BeachPieceType.longblock) { go = longblocks[visualIndex].gameObject; } else if (pt == BeachPieceType.jump) { go = jumps[visualIndex].gameObject; } else if (pt == BeachPieceType.slide) { go = slides[visualIndex].gameObject; } else if (pt == BeachPieceType.shipwreck) { go = shipwrecks[visualIndex].gameObject; } else if (pt == BeachPieceType.volleyballNet) { go = volleyballNets[visualIndex].gameObject; } go = Instantiate(go); p = go.GetComponent <BeachPiece>(); } return(p); }