/// <summary> /// Shooting using RayCast. /// </summary> protected virtual void RayBulletShootingProcess() { RaycastHit raycastHit; for (int i = 0; i < rayBullet.GetNumberBullet(); i++) { if (rayBullet.GetNumberBullet() > 1) { firePoint.localRotation = SpreadProperties.GetSpreadRotation(-rayBullet.GetVariance(), rayBullet.GetVariance()); } if (Physics.Raycast(firePoint.position, firePoint.forward, out raycastHit, fireRange)) { Debug.DrawLine(firePoint.position, firePoint.forward, Color.red); Transform hitTransform = raycastHit.transform; SendDamage(hitTransform, rayBullet.GetDamage()); if (rayBullet.GetDecalProperties() != null) { DecalProperty decalProperty = DecalHelper.GetDecalPropertyBySurface(rayBullet.GetDecalProperties(), raycastHit); GameObject decal = decalProperty.GetRandomDecal(); AudioClip decalSoundEffect = decalProperty.GetRandomSound(); if (decal != null) { PoolManager.Instantiate(decal, raycastHit.point, Quaternion.LookRotation(raycastHit.normal)); } if (decalSoundEffect != null) { audioSource.PlayOneShot(decalSoundEffect); } } AddImpulse(transform, raycastHit.point); } } }
protected virtual IEnumerator DoAttack(AttackProperties attackProperties) { WaitForSeconds hitTime = new WaitForSeconds(attackProperties.hitTime); WaitForEndOfFrame endOfFrame = new WaitForEndOfFrame(); RaycastHit raycastHit; isAttacking = true; delayTimer = Time.time; currentDelay = attackProperties.delay; yield return(endOfFrame); weaponAnimator.SetAttack(-1); yield return(hitTime); if (Physics.Raycast(attackPoint.position, attackPoint.forward, out raycastHit, attackProperties.range)) { Debug.Log(raycastHit.transform.name); if (decalProperties != null) { DecalProperty decalProperty = DecalHelper.GetDecalPropertyBySurface(decalProperties, raycastHit); GameObject decal = decalProperty.GetRandomDecal(); AudioClip decalSoundEffect = decalProperty.GetRandomSound(); if (decal != null) { PoolManager.Instantiate(decal, raycastHit.point, Quaternion.LookRotation(raycastHit.normal)); } if (decalSoundEffect != null) { audioSource.PlayOneShot(decalSoundEffect); } } Rigidbody rigidbody = raycastHit.transform.GetComponent <Rigidbody>(); if (rigidbody != null) { rigidbody.AddForceAtPosition(attackPoint.forward * attackProperties.impulse, raycastHit.point); } } }