private void CheckInteraction() { if (Input.GetMouseButtonDown(0)) { // Crear un rayo hacia el mundo 3D desde la posicion del mouse Ray ray = _mouseScreenRayProvider.CreateRay(_camera); // Revisar si el jugador hizo click sobre una moneda var selectedCoin = _coinSelector.Check(ray); // Si hizo click, recolectar esa moneda y dejar verificar interacción con otras cosas if (selectedCoin != null) { // Seleccionar la moneda selectedCoin.Collect(); return; } // Revisar si el jugador hizo click sobre el piso if (Physics.Raycast(ray, out RaycastHit hit, _layerMaskGround)) { // Indicar cual es el nuevo objetivo del jugador _navMeshAgent.SetDestination(hit.point); // Iniciar animación de correr _animator.SetBool("Running", true); } } }
void Shooting() { timer.GetDeltaTime(Time.deltaTime); timer.TimeMultiplication(shootingSpeed.Value); if (Input.GetMouseButton(0) && timer.time > 1f && ammo.HasAmmoInMag()) { Debug.Log(name + " is shooting"); selector.Check(rayProvider.CreateRay()); ammo.Shot(); if (selector.GetSelection() != null) { selector.GetSelection().GetComponent <Idamageable>().GetDamaged(damage.Value); } timer.ResetTime(0); } else if (Input.GetKeyDown(KeyCode.R)) { Debug.Log(name + " Reloaded"); ammo.Reload(); } else if (!ammo.HasAmmoInMag()) { return; } }
private void Update() { // Create the ray Ray ray = rayProvider.CreateRay(); // Check if the ray hits a selectable object selector.check(ray); // Get the selection selection = selector.GetSelection(); // Display the UI Element at the selection position if the selection is not null if (selection != null && !isInstantiated) { // Set the position of the transform on the screen itemDescription = Instantiate(itemDescriptionPrefab, this.transform); itemDescription.transform.position = Camera.main.WorldToScreenPoint(selection.position); isInstantiated = true; } if (!selection) { Destroy(itemDescription); isInstantiated = false; } }
// Update is called once per frame void Update() { //deselection response if (_currentSelection != null) { _selectionResponse.OnDeselect(_currentSelection); } _selector.Check(_rayProvider.CreateRay()); _currentSelection = _selector.GetSelection();; //selection response if (_currentSelection != null) { //if object has prerequisite and is not complete, do nothing if (_currentSelection.GetComponent <Prerequisite>() && !_currentSelection.GetComponent <Prerequisite>().Complete) { return; } _selectionResponse.OnSelect(_currentSelection); } }
private void Update() { UpdatePower(); if (Input.GetMouseButtonDown(0)) { OnLeftClick(); if (_currentClickSelection != null) { OnDrag(); } } if (Input.GetMouseButton(0)) { OnDrag(); } if (Input.GetMouseButtonUp(0)) { OnLMB_Up(); } if (Input.GetMouseButtonDown(1)) { OnRightClick(); } //HighlightCraftingMaterials(); _selector.Check(_rayProvider.CreateRay()); }
// Update is called once per frame void Update() { // Set ray variable to camera center, in FPS controller the mouse is always at the screen center // Cast a ray into the distance, if an object is hit, the hit variable will return true // Get the location of the object that was hit and then get the object // Ensure the object is selectable if (Input.touchCount > 0) { if (Input.touches[0].phase == TouchPhase.Began) { Debug.Log("Touch Pressed"); TouchTime = Time.time; //print(TouchTime); _selector.Check(_rayProvider.CreateRay()); _initialSelection = _selector.GetSelection(); } if (Input.touches[0].phase == TouchPhase.Ended) { //print(TouchTime); _selector.Check(_rayProvider.CreateRay()); _currentSelection = _selector.GetSelection(); Debug.Log("Touch Lifted/Released"); if (_currentSelection != null && _initialSelection == _currentSelection) { var ObjTags = _currentSelection.GetComponent <Tags>(); if (ObjTags.hasTag("Combinable")) { updateSelections(_currentSelection); } if (Time.time - TouchTime > 1.0) { //print("QUACK"); print(_selector.GetSelection().name); _currentLongSelection = _selector.GetSelection(); } } } } }
private void Update() { if (_currentselection != null) _selectionResponse.OnDeselect(_currentselection); _selector.Check(_rayProvider.CreateRay()); _currentselection = _selector.GetSelection(); if (_currentselection != null) _selectionResponse.OnSelect(_currentselection); }
private void ClickDestination() { selector.Check(rayProvider.CreateRay()); if (selector.GetSelection() != null) { hitInfo = selector.GetHitInfo(); SetDestination(hitInfo.point); SetWaypoint(); SetSelected(false); animator.SetBool("IsWalking", true); } }
void LateUpdate() { if (_currentSelection != null) { _selectionResponse.OnDeselect(_currentSelection); } _selector.Check(_rayProvider.CreateRay()); _currentSelection = _selector.GetSelection(); if (_currentSelection != null) { _selectionResponse.OnHover(_currentSelection); } }
// Update is called once per frame private void Update() { if (currectSelection != null) { selectionResponse.OnDeselect(currectSelection); } selector.Check(rayProvider.CreateRay()); currectSelection = selector.GetSelection(); if (currectSelection != null) { selectionResponse.OnSelect(currectSelection); } }
private void Update() { //selection if (_currentSelection != null) { _selectionResponse.OnDeselect(_currentSelection); } //determineSeelection _selector.Check(_rayProvider.CreateRay()); _currentSelection = _selector.GetSelection(); //selection if (_currentSelection != null) { _selectionResponse.OnSelect(_currentSelection); } }
void Update() { if (_currentSelection != null) { _selectionResponse.OnDeselect(_currentSelection); } var ray = _rayProvider.CreateRay(); RaycastHit hit; _selector.Check(ray); _currentSelection = _selector.GetSelection(); if (_currentSelection != null) { _selectionResponse.OnSelect(_currentSelection); } }
private void OnMouseEnter() { // Create the ray Ray ray = rayProvider.CreateRay(); // Check if the ray hits a selectable object selector.check(ray); // Get the selection selection = selector.GetSelection(); // Display the UI Element at the selection position if the selection is not null if (selection != null) { // Set the position of the transform on the screen itemDescription = Instantiate(itemDescriptionPrefab, parentUI); itemDescription.transform.position = Camera.main.WorldToScreenPoint(selection.position); } }
public void Fire() { if (_weapon.CanShoot()) { _weapon.CurrentAmmoInClip--; var hit = _rayProvider.CheckRay(_rayProvider.CreateRay()); if (hit.collider != null) { _healthProvider = hit.collider.GetComponent <IHealthProvider>(); _healthProvider?.TakeDamage(_weapon.damage); _weapon.CurrentFireRate = _weapon.fireRate; } } else if (!_weapon.CanShoot()) { _weapon.CurrentFireRate -= Time.deltaTime; } Reload(); }
private void Update() { #region Raycast & Select _selector.Check(_rayProvider.CreateRay()); var selection = _selector.GetSelection(); #endregion if (IsNewSelection(selection)) { if (_currentSelection != null) { _selectionResponse.OnDeselect(_currentSelection); } if (selection != null) { _selectionResponse.OnSelect(selection); } } _currentSelection = selection; }
public void Fire() { AmmoUI(); if (_weapon.CanShoot() && _inputProvider.Shoot) { _weapon.CurrentAmmoInClip--; _weapon.CurrentFireRate = _weapon.fireRate; _bulletFlashParticleSystem.Play(); var hit = _rayProvider.CheckRay(_rayProvider.CreateRay()); if (hit.collider != null) { _healthProvider = hit.collider.GetComponent <IHealthProvider>(); _healthProvider?.TakeDamage(_weapon.damage); } } else if (!_weapon.CanShoot()) { _weapon.CurrentFireRate -= Time.deltaTime; } }
private void Update() { if (_currentSelection != null) { _selectionResponse.OnDeselect(_currentSelection); _hoverResponse.OnDeselect(_currentSelection); } _selector.Check(_rayProvider.CreateRay()); _currentSelection = _selector.GetSelection(); if (_currentSelection != null) { _selectionResponse.OnSelect(_currentSelection); if (_currentSelection.CompareTag("Selectable")) { if (pointer != null) { pointer.GetComponent <Image>().enabled = true; //When click, execute the action on IClickResponse if (Input.GetKeyDown(action)) { _clickResponse.OnClick(_currentSelection); } } } else if (_currentSelection.CompareTag("Hoverable")) { _hoverResponse.OnSelect(_currentSelection); } } else { if (pointer != null) { pointer.GetComponent <Image>().enabled = false; } } }
// Update is called once per frame void Update() { if (!isCutting && isBoxSelectionEnabled) { Transform selection; if (Input.GetMouseButtonDown(0)) { startPos = Input.mousePosition; } if (Input.GetMouseButtonUp(0)) { DeselectAll(); ReleaseSelectionBox(); if (isBoxSelection) { isBoxSelection = false; } else { // Create the ray Ray ray = rayProvider.CreateRay(); // Check if the ray hits a selectable object selector.check(ray); // Get the selection selection = selector.GetSelection(); // We add the selection into the selection list if it is not already present if (selection != null && !selection.tag.Equals("NOT_SELECTABLE")) { string select = selection.gameObject.name; // Debug.Log("selection: " + select); if (select != null) { if (!selected.Contains(select)) { /* * selected.Add(select); * SessionEvents.current.SelectionAny(); * SessionEvents.current.ModelSelected(select); * UpdateMeshShader(selection.gameObject, selectionShader); */ Debug.Log("Selection name: " + select); if (selection.tag.Equals("Selectable")) { SelectModelFromParent(selection.gameObject); } else { SelectModel(selection.gameObject); } } else // Deselect to delete from the list of selected item { /* * selected.Remove(select); * SessionEvents.current.DeselectionAny(); * SessionEvents.current.ModelDeselected(select); * UpdateMeshShader(selection.gameObject, standardShader); */ DeselectModel(selection.gameObject); } } } else { DeselectAll(); } } } // Mouse held down if (Input.GetMouseButton(0)) { UpdateSelectionBox(Input.mousePosition); } } // isCutting }
public Ray CreateRay() { return(_rayProvider.CreateRay()); }
public void OnMouseClick() { //CREATING THE RAY var ray = _rayProvider.CreateRay(); //SHOTING THE RAY //shooting a raycast to get the tile that the player clicked if (_selector.Check(ray)) { TileField tile; _physicsCache.TryGetTileField(_selector.GetSelection(), out tile); if (_phaseManager.GetCurrentPhase() == Phase.MOVEMENT) { //Two possibilities: the field can or not have a piece if (tile.Piece != null) { // One possibility: If its a piece from the current turn, we try to highlight if (ValidateHighlight(tile.Piece)) { // Three possibilities: // If the clicked tile is the current highlighted, we only dehighlight // If the highlighted tile is null, we only highlight // If the clicked tile isn't the current highlighted, we dehighlight and highlight the clicked one if (tile == m_HighlightedTile) { Deselect(); } else if (m_HighlightedTile == null) { TrySelectEmptyAdjacents(tile); } else if (tile != m_HighlightedTile) { Deselect(); TrySelectEmptyAdjacents(tile); } } } else { //One possibilities: if there is not a piece on the field we clicked, and we already have a highlighted field, we try to move if (m_HighlightedTile != null) { //MOVE PIECE if (tile.IsHighlighting) { //If this tile is highlighted, we can move to this tile. m_HighlightedTile.MovePieceTo(tile); UpdateBoard(tile, m_HighlightedTile); Deselect(); _turnManager.NextTurn(); } } } } else if (_phaseManager.GetCurrentPhase() == Phase.POSITIONING) { //One Possibility: There's no piece on the field, we can only move to an empty space if (tile.Piece == null) { //No piece can be put in the middle on the positioning phase if (tile.Coordinates.x == 2 && tile.Coordinates.y == 2) { return; } if (_turnManager.IsWhiteTurn()) { tile.SetPiece(_pieceProvider.GetNonPlacedWhitePiece()); } else { tile.SetPiece(_pieceProvider.GetNonPlacedBlackPiece()); } _turnIndex++; // Each player places 2 pieces before the next turn if (_turnIndex % 2 == 0) { _turnManager.NextTurn(); } //when all pieces are placed if (_turnIndex == 24) { _phaseManager.StartMovementPhase(); } } } } }
// Update is called once per frame void Update() { if (!dragging && Input.GetMouseButtonDown(0)) { start = cam.ScreenToViewportPoint(Input.mousePosition); dragging = true; } if (dragging) { end = cam.ScreenToViewportPoint(Input.mousePosition); //* WE FIND THE OBJECT THAT INTERSECT WITH THE CUT ***************** // Create the ray Ray ray = rayProvider.CreateRay(); // Debug.Log(ray); // Check if the ray hits a selectable object selector.check(ray); // Get the selection if (selector.GetSelection() != null) { selection = selector.GetSelection(); } } if (dragging && Input.GetMouseButtonUp(0)) { // Finished dragging. We compute the direction of the vector formed by start and end end = cam.ScreenToViewportPoint(Input.mousePosition); dragging = false; cutDirection = end - start; // Debug.Log("Direction: " + cutDirection); if (selection != null) { // Debug.Log("Selection: " + selection.gameObject.transform + ", " + selection.name); // var coeffs = ParallelismCoefficient(selection, cutDirection, 0.0f); /* * GameObject plane = GameObject.Find("PlaneCutter"); * plane.transform.position = selection.position; * plane.transform.rotation = Quaternion.LookRotation(cutDirection); */ if (isCutting) { Debug.Log("Selection: " + selection); if (selection.parent != null) { Cutter.SplitOBJ(selection.parent.gameObject, selection, cutDirection); } else { Cutter.SplitOBJ(selection.gameObject, selection, cutDirection); } } } } // Separate the object if we do not drag anymore and the }
//On click in the game public void OnMouseClick() { //Create a ray from the camera to the mouse position var ray = _rayProvider.CreateRay(); //check if we hit some collider if (_selector.Check(ray)) { // if so, we get the correspoding cached tile associated with that collider _physicsCache.TryGetTileField(_selector.GetSelection(), out TileField tile); if (_phaseManager.Phase == Phase.MOVEMENT) { //Two possibilities: the field we clicked can/not have a piece if (tile.Piece != null) // does have a piece { // If its a piece from the current turn, we try to select if (_movementValidator.CanSelect(tile.Piece.type, _turnManager.Turn)) { // Three possibilities: // If the clicked tile is the current selected, we deselect // If there's no selected tile, we select // If the clicked tile isn't the current selected, we deselect then select the clicked one if (tile == _movementValidator.SelectedField) { _movementValidator.Deselect(); } else if (_movementValidator.SelectedField == null) { _movementValidator.Select(tile); } else if (tile != _movementValidator.SelectedField) { _movementValidator.Deselect(); _movementValidator.Select(tile); } } } else // does not have a piece { //One possibility: if there's no piece in the tile clicked, and we already have a tile selected, we try to move if (_movementValidator.SelectedField != null) { //MOVE PIECE if (tile.IsSelected) { //If this tile is highlighted, we can move to this tile. _movementValidator.SelectedField.MovePieceTo(tile); UpdateBoard(tile, _movementValidator.SelectedField); _movementValidator.Deselect(); _turnManager.NextTurn(); } } } } else if (_phaseManager.Phase == Phase.POSITIONING) { // If there's no piece on the clicked tile , we can only move to an empty space if (tile.Piece == null) { //No piece can be put in the middle in the positioning phase if (tile.Coordinates.x == 2 && tile.Coordinates.y == 2) { return; } if (_turnManager.IsWhiteTurn()) { tile.SetPiece(_pieceProvider.GetNonPlacedWhitePiece()); } else { tile.SetPiece(_pieceProvider.GetNonPlacedBlackPiece()); } _turnIndex++; // Each player places 2 pieces before the next turn if (_turnIndex % 2 == 0) { _turnManager.NextTurn(); } //when all pieces are placed, we start he movement phase if (_turnIndex == _pieceProvider.PieceCount) { _phaseManager.StartMovementPhase(); _gameFinisher.VerifyWall(); } } } } }