Question by
zafranalon · Jan 19, 2021 at 04:00 PM ·
destroyparticlesystemaccess
particleSystem has been destroyed but you are styll trying to access it
so im getting this error that particleSystem has been destroyed but i am still trying to access it
using UnityEngine.UI; using UnityEngine; using System.Collections;
public class gun : MonoBehaviour {
public float damage = 10f;
public float range = 100f;
public ParticleSystem muzzleFlash;
public Camera fpsCam;
void Update()
{
if (Input.GetMouseButtonDown(0))
{
shoot();
muzzleFlash.Play();
}
}
void shoot()
{
ParticleSystem muzzleInstance = Instantiate(muzzleFlash);
Instantiate(muzzleFlash);
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);
}
}
}
}
Comment
Your answer
Follow this Question
Related Questions
How to destroy ParticleSystem clone? 3 Answers
Using foreach to remove and delete bullet in List - C# 3 Answers
Press an image and destroy it 0 Answers
prefab not spawning on object 0 Answers
No error code? Not sure where to go? 1 Answer