Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

CS1061 Error in console

Discussion in 'Editor & General Support' started by phillsol, Jun 8, 2022.

  1. phillsol

    phillsol

    Joined:
    Mar 14, 2022
    Posts:
    2
    Hi, I'm getting errors in unity with
    error CS1061: 'DialogueReader' does not contain a definition for 'playerInRange' and no accessible extension method 'playerInRange' accepting a first argument of type 'DialogueReader' could be found

    playerInRange has the red squiggly line under it.

    I'm quite new to coding so it's pretty confusing.
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class DetectPlayer : MonoBehaviour
    6. {
    7.     public GameObject pressEtoTalkUI;
    8.     public DialogueReader reader;
    9.  
    10.     bool playerInField = false;
    11.  
    12.     private void Update()
    13.     {
    14.         if (!playerInField)
    15.             return;
    16.  
    17.         if (!reader.playerInRange)
    18.             pressEtoTalkUI.SetActive(true);
    19.         else
    20.             pressEtoTalkUI.SetActive(false);
    21.  
    22.         if (Input.GetKeyDown(KeyCode.E))
    23.         {
    24.             reader.playerInRange = true;
    25.         }
    26.     }
    27.  
    28.     private void OnTriggerEnter(Collider other)
    29.     {
    30.         if (other.CompareTag("Player"))
    31.         {
    32.             playerInField = true;
    33.         }
    34.     }
    35.  
    36.     private void OnTriggerExit(Collider other)
    37.     {
    38.         if (other.CompareTag("Player"))
    39.         {
    40.             playerInField = false;
    41.             reader.playerInRange = false;
    42.         }
    43.     }
    44. }
     
    Last edited: Jun 8, 2022
  2. phillsol

    phillsol

    Joined:
    Mar 14, 2022
    Posts:
    2
    Nevermind, it seems like i didn't reference it in another script