public bool TryCollectPiece(GeneratorPiece piece) { //All pieces to be picked up should be added to this script if (!piecesForRepair.Contains(piece)) { Debug.LogWarning("Generator piece not added to GeneratorRepair script: " + piece.GetPieceName()); return(false); } //Check if this piece can be collected // If pieces must be collected in order and the piece's index does not match the repair index, it cannot be collected bool canCollect; if (mustCollectInOrder) { if (piece == piecesForRepair[currentCollectionProgress]) { canCollect = true; } else { canCollect = false; } } else { canCollect = true; } if (canCollect) { //The piece can be collected - add it to the collected piece queue... collectedPieceQueue.Enqueue(piece); // ...and the collection UI goPiecesUIPanel.transform.parent.gameObject.SetActive(true); GameObject goPiecePreview = Instantiate(prefabUIPiecePreview, goPiecesUIPanel.transform); goPiecePreview.transform.Find("Text").GetComponent <TextMeshProUGUI>().text = piece.GetPieceName(); piece.goUIPreview = goPiecePreview; //Either increase collection progress or set generatorReapired to true // if all pieces have been collected if (currentCollectionProgress < (piecesForRepair.Length - 1)) { currentCollectionProgress++; } else { generatorReapired = true; Debug.Log("ALL GENERATOR PIECES COLLECTED!"); } //Play the collection sound for audio feedback SoundEffectPlayer.instance.PlaySoundEffect2D(pieceCollectSound); } return(canCollect); }
private void OnMouseDown() { if (canClickGenerator) { //Clicking the generator while holding at least 1 piece if (collectedPieceQueue.Count > 0) { //Remove the piece from UI and the collection queue since it has been used GeneratorPiece pieceToAdd = collectedPieceQueue.Dequeue(); Destroy(pieceToAdd.goUIPreview); //Increase the generator's repair progress currentRepairProgress++; //Hide collection UI if all pieces were used if (collectedPieceQueue.Count == 0) { goPiecesUIPanel.transform.parent.gameObject.SetActive(false); } SoundEffectPlayer.instance.PlaySoundEffect2D(repairSound); } } }