void HandleShooting(bool aiming) { RaycastHit hit; float actualSpread = currentSpread; if (aiming) { actualSpread *= .02f; } Vector3 randPos = Random.insideUnitCircle * currentSpread; Vector3 shootOrigin = gunParent.position + gunParent.TransformDirection(randPos); Ray ray = new Ray(shootOrigin, gunParent.forward); if (Physics.Raycast(ray, out hit, 100)) { IShootable shootable = hit.transform.GetComponent <IShootable>(); if (shootable != null) { shootable.OnHit(hit.point, gunParent.forward); } impactFx.SetActive(false); impactFx.transform.position = hit.point; impactFx.transform.LookAt(shootOrigin); impactFx.SetActive(true); } currentSpread += currentWeapon.spreadValue; }
private void OnTriggerExit(Collider other) { IShootable shoot = other.GetComponentInParent <IShootable>(); shoot.OnHit(other.gameObject.transform.position); Invoke("DestroyBullet", 5f); }