I cannot access any class outside the same script. C++ IDE: Unity 2019.4.29f1

Asked

Viewed 22 times

-1

EX:

Enemy:

public class Inimigo : MonoBehaviour
{
    public static int ContadorInimigo;

    public Inimigo()
    {
        ContadorInimigo++;
    }
}

The second script already

Gamecontroll:

void start()
    {
        Inimigo inimigo1 = new Inimigo();
        Inimigo inimigo2 = new Inimigo();
        Inimigo inimigo3 = new Inimigo();

        Debug.Log(Inimigo.ContadorInimigo);
    }

Note that each command is in different scripts

1 answer

0

the language you are using is C# not C++, another question I ask you to check is if the Start method is lowercase S, if it is not going to be identified as Monobehaviour method, the correct method should contain uppercase S every time.

If the method is right and it doesn’t fix your problem, try to give us more information about what problem you are presenting in your game.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.