What is wrong with my script?

The problem:

flame.particleSystem.Play();

This line does not work. It says Unity. GetComponent does not contain a definition for particlesyste.play

using UnityEngine;
using System.Collections;

public class PullTrigger : MonoBehaviour {
public ParticleSystem flame;
public ParticleSystem flame2;
public GameObject explode;
public Camera c1;
public Camera c2;
public GameObject concrete;
public AudioSource fire;
public AudioSource fire2;
public AudioSource charge;
public GameObject gun;
public Light fl;
public GameObject blood;
public GameObject steel;
public GameObject undead1;
public GameObject undead2;
public GameObject undeaddog1;
public GameObject elite3;

public Collider coll;
public Collider walls;
public float timeBetweenShots = 0.3333f; // Allow 3 shots per second
private float timestamp;
public Rigidbody u1;
public Light l1;
public Light l2;
public GameObject bar1flames;
public GameObject bar1exp;

void Start() {
coll = GetComponent();
walls = GetComponent();

flame.GetComponent();
flame2.GetComponent();
u1 = GetComponent();
StartCoroutine(Example());

}

void Awake () {

Application.targetFrameRate = 60;
}

public void Update() {
if (Input.GetButtonDown (“Cam2”)) {
c1.enabled = false;
c2.enabled = true;
} else if (Input.GetButtonUp (“Cam2”)) {
c1.enabled = true;
c2.enabled = false;
}

if (Input.GetButtonDown (“F”)) {
fl.enabled = true;
} else if (Input.GetButtonDown (“G”)) {

fl.enabled = false;
}

if (Input.GetButton (“Trig1”) && Time.time >= timestamp) {

timestamp = Time.time + timeBetweenShots;
Ray ray = new Ray (flame.transform.position, flame.transform.forward);
RaycastHit hit;

fire.Play ();

if (Physics.Raycast (ray, out hit, 100)) {

//enemies hit
if (hit.collider.gameObject.layer == 0 && hit.collider != null) {

Instantiate (concrete, hit.point, Quaternion.identity);

//Destroy (undead1, 0.01f);

}

if (hit.collider.gameObject.layer == 11 && hit.collider != null) {

Instantiate (blood, hit.point, Quaternion.identity);
Destroy (undead1, 0.01f);

Destroy (hit.transform.gameObject);
//Destroy (undead1, 0.01f);

}

}
}

//GRENADE GRENADE GRENADE GRENADE GRENADE GRENADE GRENADE

}
}
}

IEnumerator Example() {
flame.particleSystem.Play();
yield return new WaitForSeconds(0.05f);
flame.particleSystem.Stop();
}

}

Agh, my eyes. :slight_smile: Please use code tags.

As far as what is wrong, it’s most likely because you’re declaring a variable as a ParticleSystem and then you’re trying to getComponent on it. It already is a ParticleSystem. Either your variables should be gameobjects, or if you are dragging and dropping particlesystems on them, just do flame.Play() for example.

Oh, and this
flame.GetComponent();
flame2.GetComponent();

Doesn’t actually do anything. These would normally return a ParticleSystem component, but you aren’t assigning them to any variables and I’m not sure they actually return particleSystems…since the variables are ParticleSystems.

I think, these lines could be something like

flame = GetComponent<ParticleSystem>();

If not, the assignment seems to be missing or is done in the editor (check, if you did that correctly).

As flame and flame2 already are particle systems, you should be able to call

flame.Play();

directly - without using “particleSystem” in between.

If all that does not help, please note down the full error message and point out the line in which it happens.
And: Using code tags properly - Unity Engine - Unity Discussions

Thnx for the help guys. Will try it again this evening

Update:

So I cleaned the code and do as suggested.

using UnityEngine;
using System.Collections;

public class PullTrigger : MonoBehaviour {
      public Camera c1;
    public GameObject concrete;
    public ParticleSystem muzz;
    public AudioSource fire;
    public GameObject gun;
    public Light fl;
    public Light flb;
    public GameObject blood;
    public GameObject steel;
    public float timeBetweenShots = 0.1f;  // Allow 3 shots per second
    private float timestamp;

    void Update() {
      


        if (Input.GetButtonDown ("F")) {
            fl.enabled = true;
            flb.enabled = true;
        } else if (Input.GetButtonDown ("G")) {
          
            fl.enabled = false;
            flb.enabled = false;
        }

////RECOIL

        if (Input.GetButtonDown ("Trig1")) {
            gun.transform.Rotate(-1,0*Time.deltaTime,0);
            c1.transform.Rotate(-2,0*Time.deltaTime,0);

        }

        if (Input.GetButtonUp ("Trig1")) {
            gun.transform.Rotate(1,0*Time.deltaTime,0);
            c1.transform.Rotate(2,0*Time.deltaTime,0);

        }

////RECOIL

///PullTrigger

        if (Input.GetButton ("Trig1") && Time.time >= timestamp) {
          
            fire.Play ();
            muzz.Play();

            timestamp = Time.time + timeBetweenShots;
            Ray ray = new Ray (fire.transform.position, fire.transform.forward);
            RaycastHit hit;


            if (Physics.Raycast (ray, out hit, 100)) {

                if (hit.collider.gameObject.layer == 0 && hit.collider != null) {
                    Instantiate (concrete, hit.point, Quaternion.identity);
            }


                if (hit.collider.gameObject.layer == 11 && hit.collider != null) {

                    Instantiate (blood, hit.point, Quaternion.identity);
                    Destroy (hit.transform.gameObject);
                }      
            }
        }

    }
}