'ParticleSystem' does not contain a definition for 'Play'
Asked Answered
A

3

0

I’ve done a basic ParticleSystem tutorial on YT, wich plaus well in the editor. But for some reason I can’t get to start the animation from my Script.

This might come from Visual Studio that crushes the imports and stuff, but here’s my code:

using UnityEngine;
using TMPro;
  
namespace Namespace.Scoreboards
{
    public class ScoreboardEntryUI : MonoBehaviour
    {
        [SerializeField] private TextMeshProUGUI entryNameText = null;
        [SerializeField] private TextMeshProUGUI entryScoreText = null;
  
        private ParticleSystem particleEffect;
        
  
        public void Initialize(ScoreboardEntryData scoreboardEntryData)
        {
            entryNameText.text = scoreboardEntryData.entryName;
            entryScoreText.text = scoreboardEntryData.entryScore.ToString();
            particleEffect = GetComponent<ParticleSystem>();
            particleEffect.Play();
        }
    }
}

This script is attached to a Game prefab, which has the so-called Particle Systems.

160838-part.png

I get the error in console:

Assets\Scripts\ScoreboardEntryUI.cs(19,28): 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?)

I have no idea how the compiler can not get the Play() method from ParticleSystem.

Am I missing something ?

Thanks !

Applicator answered 8/4, 2024 at 19:50 Comment(0)
A
0

FOUND ANSWER: Okay so for some reason (I’m looking at you MS Visual Studio), a script named ParticleSystem.cs was created inside my Script folder, and it didn’t had a function named Play() obviously.

Solution was to delete that script, so that UnityEngine.ParticleSystem wasn’t override by my script :wink:

Applicator answered 6/6, 2023 at 2:32 Comment(0)
P
0

i have the same problem and i have a script named ParticleSystem.cs but when i changed its name the error still :confused:

Pycnidium answered 23/9, 2020 at 12:31 Comment(1)

The file and the class name must be changed.

Matronna
H
0

Just change the Script name from ParticleSystem.cs to ParticleScript.cs . Kinda late but this might help someone.

Horan answered 8/4, 2024 at 12:57 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.