Fixed RayCasts
This commit is contained in:
@ -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));
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user