Unity How to stop playing Particle System animation on the start of the Game regime?

frostysh

Newbie
Jul 31, 2018
25
6
I have a problem while trying to get trough Unity in-build tutorial, the Particle System which I need to play when the health consumables collides with a main character is also playing on the start of game mode. After a while, to understand why is that so, I am trying to disabling one-by-one things in the main character script that I thought was related to the above mentioned particle system, and after a fail, I have found the reason outside the code.



Unfortunately, after I have disable such option, the Particle System stopped to be used at all, anywhere and anytime in the game mode, which not what I want to. The particle system Consume_Health_Potions is a child object of the main character object. Those I have tried to use SetActive and GetComponentInChildren to deactivate it on the start of the game mode, but with no much success.

C:
// Start is called before the first frame update.
    void Start()
    {
        GameObject Strawberry;
        Strawberry = GetComponentInChildren<Consume_Health_Potions>();
        Strawberry.SetActive(false);
    }

The console error massage is next...

C:
Assets\Scripts\Idiotic_Ruby_Controller.cs(43,56): error CS0246: The type or namespace name 'Consume_Health_Potions' could not be found (are you missing a using directive or an assembly reference?)
 

Disturbium

Newbie
Jul 10, 2020
15
14
Hi again,

void Start()
{
GameObject Strawberry;

You are declaring Strawberry as a gameObject but you are using GetComponent(Consume...). GetComponent will return the class Consume_Health_Potions not the gameobject

Strawberry = GetComponentInChildren<Consume_Health_Potions>();
Get Component returns the Class Consume Health Potions. But Strawberry is declared as a gameobject. Invalid declaration.

Strawberry.SetActive(false);
Then you have tried to call a gameobject function.

}


Try this.

Code:
    void Start()
    {
        Consume_Health_Potions Strawberry;
        Strawberry = GetComponentInChildren<Consume_Health_Potions>();
        Strawberry.gameObject.SetActive(false);
    }
 

frostysh

Newbie
Jul 31, 2018
25
6
Try this.
Greetings Mr. Donutpunch!

Your code has been started, but the point it making a same error as my attempts before. Neverless, I have found a solution, it is not so good in terms of understanding how this mad Unity works for mineself, but it is works! I have disabled the above mentioned Particle System in the "Inspector"!



The problem resolved!