Hi guys,
So I have a parent element which has a static void function. Once a certain condition is met, I want to call that function. From some reason I can’t.
The parent element (let’s call its class “parent”) has this:
Once defined you then should put code between the curly brackets… though of course that’s not needed to compile.
Every part of that definition means something.
The static declares it static, void is its return type, PlayerDead is its name, the () says it’s a function with 0 parameters, and the curlies define the body of the method.
First static void PlayerDead means nothing and actual function is void playerdead()
So you want delete first line and rename function to public static void insfead of just void. And yes it needs to be public, but i would suggest that you use public instead of public static as static functions have issues with non static. It makes work harder if you dont fully understand what you are doing
This doesn’t make sense. The format of the line implies its a ‘field’, but the field is typed as void, which it can’t be… you can’t have a void field. That’s why you get the error:
When defining a function you need parenthesis and a body to go with the name and type:
What you’ve done here is defined a public static FIELD named PlayerDead of type void (which doesn’t make sense to the compiler).
Then you defined a private non-static function called PlayerDead (duplicate name).
[correction] sorry, it’s static in this code I pasted here, but was reading the non-static version in the code in OP
I would say just do this:
public static void PlayerDead()
{
//some code
}
But the code you have accesses non static members (primarily the transform of the objects).