- Home /
problems with particlesystem effect as a bullet tracer
first, i have a script attached to my gun that will instantiate a bullet(which has a script attached to it that handle's the raycasting) gun script:
if (Input.GetButton("Fire1"))
{
fireTime += Time.deltaTime;
if (waitTilNextFire <= 0)
{
Vector3 fireDirection = bullet.transform.forward;
fireRotation = Quaternion.LookRotation(fireDirection);
Quaternion randomRotation = Random.rotation;
float currentSpread = Mathf.Lerp(0.0f, maxBulletSpreadAngle, fireTime / timeTilMaxSpreadAngle);
fireRotation = Quaternion.RotateTowards(fireRotation, randomRotation, Random.Range(0.0f, currentSpread));
if(bullet)
Instantiate(bullet, bulletSpawn.transform.position, bulletSpawn.transform.rotation);
if(bulletSound)
holdSound = (GameObject) Instantiate(bulletSound, bulletSpawn.transform.position, bulletSpawn.transform.rotation);
waitTilNextFire = fireSpeed;
}
}
else
{
fireTime = 0.0f;
}
waitTilNextFire -= Time.deltaTime;
this is the part that handle's instantiating the bullet bullet script: RaycastHit hit;
void Awake()
{
if (Physics.Raycast(transform.position, WeaponAK.fireRotation * transform.forward, out hit, maxDist))
{
Debug.Log ("Physics statementcalled");
if (decalHitWall && hit.transform.tag == "LevelParts")
{
Debug.Log ("Has Hit the wall");
Instantiate(decalHitWall, hit.point + (hit.normal * floatInFrontOfWall), Quaternion.LookRotation(hit.normal));
}
if (decalHitWall && hit.transform.tag == "Enemy")
{
Debug.Log("hit enemy");
NormalZombie normalZombie = hit.collider.GetComponent<NormalZombie>();
normalZombie.zombieHealth -= 25;
Debug.Log(normalZombie.zombieHealth);
}
}
Destroy(gameObject);
}
this script fires the ray. (i have bullet spread so the rays wont always point to the same spot if that makes sense)
The problem i have is that i don't know how i should go about adding the particle system so that when i fire the bullet, the particlesystem will fire along the ray. I've tried making the particle system in the first script
ParticleSystem tracer;
then enabling it when i hold down left click, and disabling it when i don't hold down left click
if (Input.GetButton("Fire1")) { fireTime += Time.deltaTime; if (waitTilNextFire <= 0) { tracer.enableEmission = true;
and in the else statement adding
tacer.enableEmission = false;
but when i do this, the particle System never shows in my game. I've tried a looking up how to do this/testing different ways to go about it; but none of them have worked. Can anyone help point me in the right direction?
Your answer