Error CS1061

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

public class LivesManager : MonoBehaviour
{
    public GameObject player;
    public GameObject enemy;

    public int P1Life;
    public int P2Life;
  
    public GameObject Player1Wins;
    public GameObject Player2Wins;

    public GameObject Player1Text;
    public GameObject Player2Text;

    //This Code doesn't seemed to be acknowledged by Visual Studio
    public static int ScoreValue = 0;
    Text score;

    // Start is called before the first frame update
    void Start()
    {
        score = GetComponent<Text>();
    }

    // Update is called once per frame
    void Update()
    {
        if(P1Life <= 0)
        {
            player.SetActive(false);
            Player2Wins.SetActive(true);
        }

        if (P2Life <= 0)
        {
            enemy.SetActive(false);
            Player1Wins.SetActive(true);
        }
    }

    public void HurtP1()
    {
      P1Life -= 1;
        Player2Text.ScoreValue += 10;
    }

    public void HurtP2()
    {
        P2Life -= 1;
        Player1Text.ScoreValue += 10;
    }
}

Hi There I am working on a Multiplayer Score System and with my script it’s complaining about Error CS1061 complaining that I don’t have the right Method?

Here is the message I got from it
Assets\Scripts\LivesManager.cs(50,21): error CS1061: ‘GameObject’ does not contain a definition for ‘ScoreValue’ and no accessible extension method ‘ScoreValue’ accepting a first argument of type ‘GameObject’ could be found (are you missing a using directive or an assembly reference?)

What am I doing wrong here?

The error pretty much says what the issue is. There is no property/variable that exists within a plain old gameobject called ScoreValue. What is score value? A variable inside a script? A script itself? Unity doesn’t know, because it’s just a plain old gameobject.

In either case, you need to get the component you’re trying to access the method/variables from using GetComponent<>().

The variable names imply they’re UI elements. Should you be storing them as Text component and changing the text on the UI element instead?

Remember: NOBODY memorizes error codes. The error code is absolutely the least useful part of the error. It serves no purpose at all. Forget the error code. Put it out of your mind.

The important parts of an error message are:

  • the description of the error itself (google this; you are NEVER the first one!)
  • the file it occurred in (critical!)
  • the line number and character position (the two numbers in parentheses)

All of that information is in the actual error message and you must pay attention to it. Learn how to identify it instantly so you don’t have to stop your progress and fiddle around with the forum.

How to understand compiler and other errors and even fix them yourself: