0

Receiving the "The modifier 'private' is not valid for this item" error. Been searching for a while and nothing seemed to work and was wondering if someone could point out something I may have missed. This is part of a Unity Tutorial and I don't know where I went wrong (sorry this is my first time posting on any kind of coding forum and thanks in advance).

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

namespace UnityStandardAssets.Characters.FirstPerson
{

    public class Npc1 : MonoBehaviour
    {
        public GameObject triggerText;
        public GameObject DialogueObject;
        public RigidbodyFirstPersonController rigid;
        public bool hasTalked = false;
        private void OnTriggerStay(Collider other)
        {

            if (other.gameObject.tag == "Player")
            {

                triggerText.SetActive(true);
                if (Input.GetKeyDown(KeyCode.E))
                {

                    if (!hasTalked)
                    {

                        other.gameObject.GetComponent<PlayerData>().DialogueNumber = 1;
                        DialogueObject.SetActive(true);
                        rigid.enabled = false;
                        Cursor.lockState = CursorLockMode.None;
                        Cursor.visible = true;
                        triggerText.SetActive(false);
                    }
                    else
                    {
                        other.gameObject.GetComponent<PlayerData>().DialogueNumber = 1.5f;
                        DialogueObject.SetActive(true);
                        rigid.enabled = false;
                        Cursor.lockState = CursorLockMode.None;
                        Cursor.visible = true;
                        triggerText.SetActive(false);

                    }

                }

            }

             private void OnTriggerExit(Collider other)
             {

                triggerText.SetActive(false);
             }

        }

    }

 
}
  • 1
    Reference: https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/local-functions – madreflection Jan 09 '22 at 02:39
  • 2
    *"Unlike a method definition, a local function definition cannot include the member access modifier. Because all local functions are private, including an access modifier, such as the private keyword, generates compiler error CS0106, "The modifier 'private' is not valid for this item.""* – madreflection Jan 09 '22 at 02:39
  • Yeah thanks. Sorry for asking an already answered question. – Demonsaber Jan 09 '22 at 02:42

0 Answers0