Fixed RayCasts

This commit is contained in:
2022-04-18 15:42:54 +07:00
parent 2fd9694679
commit 4bc5cb5ed2
3 changed files with 5264 additions and 4 deletions

View File

@ -66,7 +66,8 @@ public class scr_CharacterController : MonoBehaviour
public float range = 100f;
public Camera fpsCam;
public ParticleSystem muzzleFlash;
public GameObject impactEffect;
private void Awake()
{
defaultInput = new DefaultInput();
@ -88,7 +89,7 @@ public class scr_CharacterController : MonoBehaviour
characterController = GetComponent<CharacterController>();
cameraHeight = cameraHolder.localPosition.y;
if (currentWeapon)
{
currentWeapon.Initialise(this);
@ -110,10 +111,19 @@ public class scr_CharacterController : MonoBehaviour
void Shoot()
{
muzzleFlash.Play();
RaycastHit hit;
if (Physics.Raycast(fpsCam.transform.position, fpsCam.transform.forward, out hit, range))
{
Debug.Log(hit.transform.name);
Target target = hit.transform.GetComponent<Target>();
if (target != null)
{
target.TakeDamage(damage);
}
Instantiate(impactEffect, hit.point, Quaternion.LookRotation(hit.normal));
}
}