L
L
Loshka242021-12-23 13:32:12
Unity
Loshka24, 2021-12-23 13:32:12

How to fix error CS 0120?

There is such code, IncomeAll () is used in another script, I know that I need to add the static modifier to Text, but then I will not be able to assign a field with text in the Unity editor.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class Income : MonoBehavior
{
public static int incomewoodg, incomegoldg, incomerockg,rock,gold,wood;
public Text counterwood, countergold, counterrock;//Error CS 0120
public static bool Hod;
void Start()
{
counterwood.text = "4";
countergold.text = "500";
counterrock.text="4";
incomewoodg = 4;
incomegoldg = 150;
incomerockg = 4;
rock=4;
gold = 500;
wood = 4;
}
void OnMouseUpAsButton()
{
rock += incomerockg;
gold += incomegoldg;
wood += incomewoodg;
Incomeall();
}
public static void Incomeall()
{
counterwood.text = wood.ToString();
countergold.text = gold.ToString();
counterrock.text = rock.ToString();

}

}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
freeExec, 2021-12-23
@freeExec

One line - one variable declaration at a time.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question