Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice
  4. Dismiss Notice

CS1061 error

Discussion in 'Scripting' started by Polud, May 23, 2020.

  1. Polud

    Polud

    Joined:
    Aug 8, 2017
    Posts:
    8
    I'm making a prototype FPS game, and I want my gun to play a particle system while shooting. I declared it in the class and selected it when the script was put on the gun. But I get this error:

    Assets\GunShootPistol.cs(24,15): error CS1061: 
    'ParticleSystem' does not contain a definition for 'play' and no accessible extension method 'play' accepting a first argument of type 'ParticleSystem' could be found
    (are you missing a using directive or an assembly reference?)


    The code is:

    Code (CSharp):
    1. using System;
    2. using UnityEngine;
    3.  
    4. public class GunShootPistol : MonoBehaviour
    5. {
    6.     public float damage = 10f;
    7.     public float range = 50f;
    8.  
    9.     public Camera Cam;
    10.     public ParticleSystem flash;
    11.  
    12.     // Update is called once per frame
    13.     void Update()
    14.     {
    15.         if (Input.GetButtonDown("Fire1"))
    16.         {
    17.             BulletShoot();
    18.         }
    19.     }
    20.  
    21.     void BulletShoot()
    22.     {
    23.  
    24.         flash.play();
    25.  
    26.         RaycastHit hit;
    27.         if (Physics.Raycast(Cam.transform.position, Cam.transform.forward, out hit, range)) {
    28.             Debug.Log(hit.transform);
    29.  
    30.            ShootingThings target = hit.transform.GetComponent<ShootingThings>();
    31.  
    32.             if (target !=null)
    33.             {
    34.                 target.TakeDMG(damage);
    35.             }
    36.         }
    37.     }
    38. }
    39.  
    The script should play the particle system, but instead it says that it's not containing the play function. I don't know what can I do, and if someone would help me out, I'd really appreciate it.
     
  2. Ramojus

    Ramojus

    Unity Technologies

    Joined:
    Nov 18, 2019
    Posts:
    8
    Hi!

    You're attempting to use a non-existing method - the one you're looking for is
    Play()
    (notice the capitalized P)
     
  3. Polud

    Polud

    Joined:
    Aug 8, 2017
    Posts:
    8
    It works, thanks!