Click here to Skip to main content
15,886,004 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
using UnityEngine;

public class ModMenuScript : MonoBehaviour {

    public bool hack1;
    public bool hack2;
    public bool hack3;
    public string string1;
    public string string2;
    public string string3;
    public bool ShowHide = false;

    void OnGUI() {

        if (GUI.Button(new Rect(20, 20, 130f, 30f), "SHOW/HIDE"))
        {
            ShowHide = !ShowHide;
        }

        if (ShowHide)
        {
            GUI.Box(new Rect(20, 50, 180, 150), "iAndroHacker's mod menu");
            if (GUI.Button(new Rect(25, 80, 170f, 30f), string1))
            {
                hack1 = !hack1;
            }
            if (GUI.Button(new Rect(25, 115, 170f, 30f), string2))
            {
                hack2 = !hack2;
            }
            if (GUI.Button(new Rect(25, 150, 170f, 30f), string3))
            {
                hack3 = !hack3;
            }
        }

        if (hack1)
        {
            string1 = "Unlimited armor <color=green>ON</color>";
            hack1 = false;
        }
        else
        {
            string1 = "Unlimited armor <color=red>OFF</color>";
            hack1 = true;
        }

        if (hack2)
        {
            string2 = "Unlimited team health <color=green>ON</color>";
            hack2 = false;
        }
        else
        {
            string2 = "Unlimited team health <color=red>OFF</color>";
            hack2 = true;
        }

        if (hack3)
        {
            string3 = "Unlimited coins <color=green>ON</color>";
            hack3 = false;
        }
        else
        {
            string3 = "Unlimited coins <color=red>OFF</color>";
            hack3 = true;
        }
    }
}




I got An error 
	An object reference is required for the non-static field, method, or property 'ModMenuScript.ShowHide' main.cs

still it is showing for everything 


What I have tried:

I have tried to compile

it shows that error
Posted
Updated 1-Feb-18 0:33am

1 solution

It looks you are referencing ModMenuScript.ShowHide in your program main function. Since main is static it cannot access the non-static ShowHide property: you need an instance (an object) of the ModMenuScrip class in order to access it. Something like
C#
static void main()
{
  ModMenuScript mms = new ModMenuScript(); 
  //..
  mms.ShowHide = true;  
  //..
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900