public class MainMenu : MonoBehaviour {
public Texture playsprite;
public float playtextureY;
public float playtextureX;
public Texture clickedplaysprite;
void OnGUI(){
//animator = GetComponent<Animator> ();
if (GUI.Button(newRect(Screen.width/2.7f,Screen.height/3,Screen.width/4,Screen.height/10),playsprite,"")){
playsprite=clickedplaysprite;
Darkfadeinout.EndScene();
//Application.LoadLevel(1);
}
}
}
And hereās my code which should on clicking the playsprite fade screen into black and loadlevel 1 appears problem like in titleā¦
An object reference is required to access non-static member `Darkfadeinout.EndScene()ā
public class Darkfadeinout : MonoBehaviour {
public float fadeSpeed = 1.5f;
private bool sceneStarting = true;
public void EndScene(){
guiTexture.enabled = true;
FadeToBlack ();
if(guiTexture.color.a >= 0.95f)
{
Application.LoadLevel(1);
}
}
}
You are accessing a method like you would a static class and as message says your class is not static.
Darkfadeinout.EndScene();
Either make your Darkfadeinput class static or add a reference to the class Darkfadeinput in your MainMenu class:
Other way i changed darkfadeinout class on public static class and Console says āStatic class Darkfadeinout' cannot derive from type UnityEngine.MonoBehaviourā. Static classes must derive from objectā
I did it, but now Console says
āNullReferenceException
Darkfadeinout.EndScene () (at Assets/Darkfadeinout.cs:33)
MainMenu.OnGUI () (at Assets/MainMenu.cs:29)ā
:<
Last time I checked, you cannot use new with a mono behavior. Get rid of new statement, make the variable public or use serialize able atrribute, add darkfade to game object, and drag drop it in inspector or use get component.
Well this doesnāt have anything to do with your NullReferenceException, but you call the ādarknessscript.EndScene();ā after you called āApplication.LoadLevel(1);ā. Unless Iām mistaken, as soon as it executes the LoadLevel itās not longer going to execute anything after that, because everything in the current level gets destroyed (unless itās marked āDontDestroyOnLoadā).
Also, ādarknessscript.EndScene();ā already has a line in it that does āApplication.LoadLevel(1);ā.
Yeah i know. I didnāt see that. I wrote application load level cause darknessscript. End scene didnāt work. And for now is like that. There was no application load level when I was posting. Sorry. I want it to work with end scene without application load level