validate existence of class in C # unity3d

0

I am developing a game, in which one of the characters I have added a script for life control. At the beginning of the game, that character is an NPG. At a certain moment, he must become an enemy or ally (according to the player's choice).

For this, my idea is, once the choice is made, to add a component that I have named Life. It is a Script in C #, obtained from a previous project, with several functions and among them the Deadfx function:

void Deadfx()
{
    MaquinaEstados machine = gameObject.GetComponent<MaquinaEstados>();
    if (machine != null)
        Destroy(machine, 0f);

    print(gameObject.name + " is dead");
    if (anim != null)
    {
        anim.SetTrigger("Dead");
    }
    Destroy(gameObject, 10f);
}

This script gives me an error in the first line, because currently in the project there is no MaquinaEstados class. Of course, if I add that component, this is solved. But my intention is to verify, in some way, that the MaquinaEstados class exists BEFORE trying to obtain that component, and in this way leave my script prepared for future projects.

Does anyone know how this check can be done? in PHP I would do something like

if (object instanceOf MaquinaEstados) ...

(but of course, this is not php ...

    
asked by Jakala 27.05.2018 в 04:58
source

0 answers