private void HandleSelectionFromStateMachine(GameObject chosenFromStateMachine) { selection = chosenFromStateMachine.transform; PieceShoot scriptShoot = selection.GetComponent <PieceShoot>(); GameObject arrowInst = Instantiate(arrow); scriptShoot.shootMode = true; arrowInst.transform.position = chosenFromStateMachine.transform.position; arrowInst.GetComponent <ArrowScript>().cube = chosenFromStateMachine.transform; }
/// <summary> /// /// </summary> /// <param name="jenga"></param> /// <returns>If the turn is finished</returns> public bool Tick(GameObject jenga) { if (Input.GetKey(KeyCode.Alpha1)) { dragging = true; } if (Input.GetKey(KeyCode.Alpha2)) { dragging = false; } if (!_currentPiece) { _currentPiece = jenga; _currentPieceShoot = jenga.GetComponent <PieceShoot>(); _currentPieceDrag = jenga.GetComponent <PieceDragAndDropScript>(); } List <GameObject> floorPieces = _tower.PiecesOnTheFloor(); if (_tower.badPlaced.Count > 0 && !_tower.badPlaced.Contains(_currentPiece)) { Debug.Log("LOSE"); return(true); } if (floorPieces.Count > 1 || floorPieces.Count == 1 && floorPieces.IndexOf(_currentPiece) <= -1) { Debug.Log("LOSE"); return(true); } if (floorPieces.Count == 1) { _currentPiece.GetComponent <PieceCheckCollision>().OnDestroy(); return(true); } if (dragging) { _currentPieceDrag.DragJenga(); return(false); } _currentPieceShoot.DragJenga(); return(false); }
private GameObject HandleHit(RaycastHit hit) { if (_topPieces.Contains(hit.transform.gameObject)) { return(null); } if (selection && hit.transform != selection.transform) { Renderer selectionRenderer = selection.GetComponent <Renderer>(); selectionRenderer.material = selection.GetComponent <PieceOriginalMaterial>().originalMaterial; selection = hit.transform; return(null); } if (Input.GetMouseButtonDown(0) && !alreadySelected) // Shoot jenga { selection = hit.transform; PieceShoot scriptShoot = selection.GetComponent <PieceShoot>(); GameObject arrowInst = Instantiate(arrow); scriptShoot.shootMode = true; arrowInst.transform.position = hit.transform.position; arrowInst.GetComponent <ArrowScript>().cube = hit.transform; return(selection.gameObject); } if (Input.GetMouseButtonDown(1) && !alreadySelected) //Drag and drop jenga { mode = 1; selection = hit.transform; var scriptMove = selection.GetComponent <PieceDragAndDropScript>(); scriptMove.dragMode = true; return(selection.gameObject); } selection = hit.transform; Renderer selectionRendererEnd = selection.GetComponent <Renderer>(); selectionRendererEnd.material = mat; return(null); }