#You are trying to create a MonoBehaviour using the 'new' keyword WARNING

1 messages · Page 1 of 1 (latest)

rocky lotus
#
{
    public Classe_attaccabrighe()
    {
        Vita_classe = 200;
    }
}
#
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Gestore_classi : MonoBehaviour
{
    private Base_classi guerrafondaio = new Classe_guerrafondaio();
    private Base_classi armaiolo = new Classe_armaiolo();
    private Base_classi velocista = new Classe_velocista();
    private Base_classi doc = new Classe_doc();
    private Base_classi piromane = new Classe_piromane();
    private Base_classi marksman = new Classe_marksman();
    private Base_classi attacabrighe = new Classe_attaccabrighe();
    public static int vita_max_classe;
    void Start()
    {
        string nome_classe = LettoreXML.Classe;
        switch(nome_classe)
        {
            case "Guerrafondaio":
                Gestore_gerrafondaio();
                break;

            case "Velocista":
                Gestore_velocista();
                break;

            case "Attaccabrighe":
                Gestore_attacabrighe();
                break;
                
            case "Doc":
                Gestore_doc();
                break;

            case "Marksman":
                Gestore_marksman();
                break;

            case "Armaiolo":
              Gestore_armaiolo();
              break;

            case "Piromane":
              Gestore_piromane();
              break;
        }
    }private void Gestore_marksman()
    {
    vita_max_classe = marksman.vita_classe;
    }private void Gestore_piromane()
    {
    vita_max_classe = piromane.vita_classe;
    } private void Gestore_armaiolo()
    {
    vita_max_classe = armaiolo.vita_classe;
    }private void Gestore_doc()
    {
    vita_max_classe = doc.vita_classe;
    }private void Gestore_attacabrighe()
    {
    vita_max_classe = attacabrighe.vita_classe;
    } private void Gestore_velocista()
    {
    vita_max_classe = velocista.vita_classe;
    } private void Gestore_gerrafondaio()
    {
     vita_max_classe = guerrafondaio.vita_classe;
    }   
}
#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Base_classi 
{
    public int vita_classe;

    public int Vita_classe
    {
        get { return vita_classe; }
        set { vita_classe = value; }
    }
}
#

this are the scripts, for the first one there are other 6 scripts like that

shrewd nacelle
undone orchid
#

either use a regular class, that does not inherit from a MonoBehaviour
or use gameObject.AddComponent to attach your MonoBehviour to a gameObject

shrewd nacelle
#

Is this warning okay?
Yesn't.

undone orchid
#

the problem is, if you create a MonoBehaviour with new, it won't do much, it isn't added to any object and isn't added to the unity event lifecycle

#

which would invalidate the whole purpose of using MonoBehaviours in the first place, in which case just use a regular class that doesn't inherit from MonoBehaviour

rocky lotus
#

ok thx

undone orchid
#

note:
gameObject.AddComponent<YourBehaviour>();

will create the monoBehaviour and attach it, so you'd use that to replace the new ();

rocky lotus
undone orchid
#

that seems fine, seems like a regular class, did you save your script in the code editor?

#

maybe one of these still inherits from monobehaviour

 private Base_classi guerrafondaio = new Classe_guerrafondaio();
    private Base_classi armaiolo = new Classe_armaiolo();
    private Base_classi velocista = new Classe_velocista();
    private Base_classi doc = new Classe_doc();
    private Base_classi piromane = new Classe_piromane();
    private Base_classi marksman = new Classe_marksman();
    private Base_classi attacabrighe = new Classe_attaccabrighe();
rocky lotus
#

the only monobehavior class is Gestore_classi

undone orchid
#

maybe it's an old warning and you just have to clear your console then

rocky lotus
#

ok