[SOLVED] Member cannot be accessed with an instance reference; qualify it with a type name instead

public class CreditsButton : MonoBehaviour
{
    [SerializeField]
    public GameObject newGameButton;
   
    public GameObject[] mainMenu;
    public GameObject[] credits;
   
    public GameObject settingsButton;
    public SettingsButton settingsScript;
   
    public Image newGameButtonSprite;
   
    void Start()
    {
        newGameButtonSprite = newGameButton.GetComponent<Image>();
        settingsButton = GameObject.Find("Settings");
        settingsScript = settingsButton.GetComponent<SettingsButton>();
        mainMenu = GameObject.FindGameObjectsWithTag("MainMenuTag");
        settingsScript.mainMenuRef = mainMenu;
        credits = GameObject.FindGameObjectsWithTag("CreditsTag");
        foreach(GameObject credit in credits)
        {
            credit.SetActive(false);
        }
    }
...
public class SettingsButton : MonoBehaviour
{
    [SerializeField]
    public GameObject newGameButton;
   
    public Image newGameButtonSprite;
   
    public static GameObject[] mainMenuRef;
    public GameObject[] settings;
   
    void Start()
    {
        newGameButtonSprite = newGameButton.GetComponent<Image>();
        settings = GameObject.FindGameObjectsWithTag("SettingsTag");
        foreach(GameObject setting in settings)
        {
            setting.SetActive(false);
        }
    }
...

How can I do it like I want to?

1 Like

mainMenuRef is static, so you can’t access it through an instance. I don’t know if you really intend for it to be static, but either remove the static or access it like this

SettingsButton.mainMenuRef = mainMenu;
1 Like

That was it. Thank you :wink:

1 Like

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMovement : MonoBehaviour
{
public CharacterController controller;
public float gravity = 9.81f;
public float speed = 12f;
public Transform groundCheck;
public float grouondDistance = 0.4f;
public LayerMask groundMask;
public Physics Physiscs;

Vector3 velocity;
bool isGrounded;
// Update is called once per frame
void Update()
{
isGrounded = Physiscs.CheckSphere(groundCheck.position, grouondDistance, groundMask);
if(isGrounded && velocity.y < 0)
{
velocity.y = -2f;
}
float x = Input.GetAxis(“Horizontal”);
float z = Input.GetAxis(“Vertical”);
Vector3 move = transform.right * x + transform.forward * z;
controller.Move(move * speed * Time.deltaTime);
velocity.y -= gravity * Time.deltaTime;
controller.Move(velocity * Time.deltaTime);
}
}

mine says: Assets\Scripts\PlayerMovement.cs(23,22): error CS0176: Member ‘Physics.CheckSphere(Vector3, float, int)’ cannot be accessed with an instance reference; qualify it with a type name instead

Maybe you should try Physics.CheckSphere instead?

What is this for exactly?

That’s fine but please create your own threads and not hijack an existing (old) thread just because it has the same compilation error. These kinds of errors are from you typing stuff that isn’t correct, it’s not the SAME problem.

Also, always use code-tags when posting code.

Thanks.

1 Like

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Dist : MonoBehaviour
{
public GameObject player;
private float dist;
public float maxDist;
public Outline outline;

// Start is called before the first frame update
private void Start()
{

}

// Update is called once per frame
private void Update()
{
dist = Vector3.Distance(player.transform.position, transform.position);

if (dist <= maxDist)
{
outline.OutlineMode = outline.OutlineMode.OutlineHidden;
}
}
}

Assets/Script/Dist.cs(25,35): error CS0176: Member ‘Outline.Mode.OutlineHidden’ cannot be accessed with an instance reference; qualify it with a type name instead

Please do not hijack threads and try to read the Community Code of Conduct before proceeding. If you are going to hijack a thread then please read what the thread is about. This thread is marked as resolved and even describes what the problem is which is your understanding of Static members.

Please create your own threads and always post code using code-tags and not plain text.