D
D
DiseaseC2021-04-15 21:33:42
C++ / C#
DiseaseC, 2021-04-15 21:33:42

How to make a variable shared in Unity, not separate for each GameObject?

There are several cells. I count the number of clicks on the cell, and when it becomes equal to clicksToWin, then the cell is considered "passed", and winPoint should increase by 1. And when winPoint becomes equal to the given value, then the level is won.
Simplified it looks like this:

public GameObject cell;

private int clicks = 0;
public int clicksToWin;

public int winPoint = 0;

public void ClickOnCell() {
    clicks++;

    if (clicks == clicksToWin)
          winPoint++;
}

But here the problem is that winPoint, like clicks and clicksToWin, is different for each individual cell. How can I make the clicksToWin variable "shared" to count the number of correctly clicked cells?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
ReyGrau, 2021-04-20
@DiseaseC

Use static variables

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question