Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

error CS1061: Type `UnityEngine.ParticleEmitter'

Discussion in 'Scripting' started by Akimania, Sep 25, 2018.

  1. Akimania

    Akimania

    Joined:
    Dec 8, 2016
    Posts:
    8
    hello, can someone help me adapt this old code, which is no longer compatible with the 2018 version.
    on several lines

    Assets/AnimationState Controller/Scripts/SchootController.cs(26,52): error CS1061: Type 
    `UnityEngine.ParticleEmitter' does not contain a definition for `emit' and no extension method `emit' of type
    `UnityEngine.ParticleEmitter' could be found. Are you missing an assembly reference?


    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. public class SchootController : MonoBehaviour
    4. {
    5.     public Transform Bullet;    // Bullet Paricle
    6.     public Transform Smoke;     // Smoke Paricle
    7.     public Transform Bright;    // Bright Paricle
    8.     public Transform Fire;      // Fire1 Paricle
    9.     public Transform Fire2;     // Fire2 Paricle
    10.  
    11.     private bool IsReloading;
    12.  
    13.     void Update ()
    14.     {
    15.         // if the input button Reload is pressed wait for reload time
    16.         if (Input.GetButtonDown("Reload"))
    17.         {
    18.             IsReloading = true;
    19.             StartCoroutine(reloadwait());
    20.         }
    21.  
    22.         // if the input button 'fire1' is pressed and isn't reloading then enable the paricle effects
    23.         if (Input.GetButton("Fire1") && !IsReloading)
    24.         {
    25.             Bullet.GetComponent<ParticleEmitter>().emit = true;
    26.             Smoke.GetComponent<ParticleEmitter>().emit = true;
    27.             Bright.GetComponent<ParticleEmitter>().emit = true;
    28.             Fire.GetComponent<ParticleEmitter>().emit = true;
    29.             Fire2.GetComponent<ParticleEmitter>().emit = true;
    30.         }
    31.  
    32.         // if the input button 'fire1' is NOT pressed or is reloading then disable the paricle effects
    33.         else
    34.         {
    35.             Bullet.GetComponent<ParticleEmitter>().emit = false;
    36.             Smoke.GetComponent<ParticleEmitter>().emit = false;
    37.             Bright.GetComponent<ParticleEmitter>().emit = false;
    38.             Fire.GetComponent<ParticleEmitter>().emit = false;
    39.             Fire2.GetComponent<ParticleEmitter>().emit = false;
    40.         }
    41.     }
    42.  
    43.     // Wait for reloading to shoot again
    44.     IEnumerator reloadwait()
    45.     {
    46.         yield return new WaitForSeconds(2.7f);
    47.         IsReloading = false;
    48.  
    49.     }
    50. }
    51.  
     
  2. GroZZleR

    GroZZleR

    Joined:
    Feb 1, 2015
    Posts:
    3,201
  3. alpha_rat

    alpha_rat

    Joined:
    Apr 18, 2015
    Posts:
    12
    Your Bullet references a Transform and not a Game Object.
    You should also try to access the "Emission" module of the ParticleSystem component :

    Code (CSharp):
    1. Bullet.gameObject.GetComponent<ParticleSystem>().emission
    And if you want to turn it off :

    Code (CSharp):
    1. Bullet.gameObject.GetComponent<ParticleSystem>().emission.enabled = false;
     
    Akimania likes this.
  4. Akimania

    Akimania

    Joined:
    Dec 8, 2016
    Posts:
    8
    #alpha_rat
    it's exactly his, thank you very much problem solved ;)
     
    alpha_rat likes this.