Figured It out
Cannot access a nonstatic member of outer type via nested type
Hello, I am making this script which references another script. How can I fix this error? I have searched a lot and I know I could make it static but I need a public so I can add a gameobject in the inspector. Do you have any ideas? Here/s my script:
using UnityEngine;
public class DeathCanvass : MonoBehaviour {
public GameObject DeathCanvas;
public class ScriptB {
// Assign by dragging the GameObject with ScriptA into the inspector before running the game.
public Healthbar m_someOtherScriptOnAnotherGameObject;
void Start() {
m_someOtherScriptOnAnotherGameObject.die();
}
void die(){
DeathCanvas.SetActive(true);
}
}
}
Why have you a nested class? It seems you are trying to call the die
of the Healthbar
class, but this function is defined inside the ScriptB
class, not the Healthbar
one.
Thanks for the reply! What do you mean? Basically I have a Healthbar script but I am unable to add in so the canvas is activated from that script. So I tried to connect that script function in this one, have I done something wrong while doing that? :)
Why don't you keep it simple like this?
public class DeathCanvass : $$anonymous$$onoBehaviour
{
public GameObject DeathCanvas;
void Start()
{
Die();
}
void Die()
{
DeathCanvas.SetActive(true);
}
}
The problem with that is it activates the canvas straight away. I want it so once I die(which is defined in the other script) the canvas will come up