public override HitBox HitTest() { if (!IsVisible()) { return(HitBox.Miss); } HitBox hit; if ((hit = _scrollBar.HitTest()).IsHit) { return(hit); } for (int i = VerticalScrollIndex; i < _items.Count && i - VerticalScrollIndex < VerticalMaxVisibleItems; i++) { if (!_items[i].HitTest()) { continue; } _selectedItem = _items[i]; OnSelect?.Invoke(_items[i].Value); return(HitBox.Hit(this)); } _clickable.HitTest(MouseButton.Left); if (_clickable.IsDown(MouseButton.Left)) { return(HitBox.Hit(this)); } return(HitBox.Miss); }
public void ReceiveHit(HitBox hitbox) { foreach (var d in defense) { HitBox worldSpace = new HitBox(d, transform); if (hitbox.Hit(worldSpace)) { Debug.Log("Hit! "); Debug.DrawLine(worldSpace._position, worldSpace._position + worldSpace._size, Color.green, 15f); Debug.DrawLine(hitbox._position, hitbox._position + hitbox._size, Color.magenta, 15f); handler.ReceiveHit(hitbox); } } }
void OnTriggerEnter(Collider collider) { HitBox hitBox = collider.GetComponent <HitBox>(); if (hitBox) { if (shooter.tag == hitBox.transform.parent.tag) { return; } hitBox.Hit(); gameObject.SetActive(false); } }
public override HitBox HitTest() { if (!IsVisible()) { return(HitBox.Miss); } switch (_state) { case ButtonStates.Normal: if (MouseManager.IsUp(MouseButton.Left)) { return(HitBox.Miss); } if (Bounds.Contains(UiState.Mouse.Position)) { _state = ButtonStates.Pressed; IsDirty = true; return(HitBox.Hit(this)); } break; case ButtonStates.Pressed: if (MouseManager.IsUp(MouseButton.Left)) { OnClick?.Invoke(); _state = ButtonStates.Normal; IsDirty = true; } else { return(HitBox.Hit(this)); } break; } return(HitBox.Miss); }
// Update is called once per frame void Update() { coolDownTimer.Update(Time.deltaTime); reloadTimer.Update(Time.deltaTime); if (Input.GetKeyDown(KeyCode.L)) { flashlight.enabled = !flashlight.enabled; MainAudioSource.PlayOneShot(flashlightClip); } if (Input.GetKeyDown(reloadKey) && reloadTimer.Finished) { if (remainingRounds >= 1) { gunAudioSource.PlayOneShot(ReloadClip); reloadTimer.Reset(); int reloadCount = Mathf.Min(magSize - rounds, remainingRounds); rounds += reloadCount; remainingRounds -= reloadCount; } else { gunAudioSource.PlayOneShot(GunEmptyClip); } } if (reloadTimer.Finished && coolDownTimer.Finished && Input.GetMouseButtonDown(0)) { if (rounds <= 0) { gunAudioSource.PlayOneShot(GunEmptyClip); } else { Animator.SetTrigger("Fire"); shellEffect.Play(); coolDownTimer.Reset(); gunAudioSource.PlayOneShot(GunShotClip); rounds--; LookManager.Instance.Recoil(); Vector3 rayOrigin = FPSCam.ViewportToWorldPoint(new Vector3(0.5f, 0.5f, 0.0f)); RaycastHit hit; if (Physics.Raycast(rayOrigin, FPSCam.transform.forward, out hit, Range)) { HitBox hitBox = hit.collider.GetComponent <HitBox> (); // If there was a health script attached if (hitBox != null) { // Call the damage function of that script, passing in our gunDamage variable hitBox.Hit(hit); } else { BombHitBox bombHitBox = hit.collider.GetComponent <BombHitBox> (); if (bombHitBox != null) { Bomb bomb = bombHitBox.transform.parent.gameObject.GetComponent <Bomb> (); bomb.Explode(); } } } } } }