- Home /
Question by
KashewSucksAtCoding · Jul 23, 2020 at 08:46 AM ·
c#fpsshooting
How do I make my bullet tracers show when shooting in the air?
My bullet tracer script only works when I shoot an object, I want it to work when I shoot in the air as well. Can someone help me with this?
My Script:
void Shoot()
{
audioSource.Play();
muzzleflash.Play();
recoil.Fire();
RaycastHit hit;
if (Physics.Raycast(shootPoint.position, shootPoint.transform.forward, out hit, range))
{
UnityEngine.Debug.Log(hit.transform.name);
player2Health target = hit.transform.GetComponent<player2Health>();
SpawnBulletTrail(hit.point);
if (target != null)
{
target.TakeDamage(damage);
}
}
}
void SpawnBulletTrail(Vector3 hitPoint)
{
GameObject bulletTrailEffect = Instantiate(bulletTrail.gameObject, shootPoint.position, Quaternion.identity);
LineRenderer lineR = bulletTrailEffect.GetComponent<LineRenderer>();
lineR.SetPosition(0, shootPoint.position);
lineR.SetPosition(1, hitPoint);
Destroy(bulletTrailEffect, 3f);
}
}
Comment
Your answer
Follow this Question
Related Questions
Gun Shooting Animation Won't Play 0 Answers
Reload Ammo is not working 0 Answers
Reload Ammo is not working 1 Answer
Multiple Cars not working 1 Answer
shooting multiple enemies using raycast 2 Answers