Hello, everybody!
This is my issue: I have a script that moves NPCs along different environments in pre-established locations. The way I do this is by generating a random number, and assigning each number to the location.
However, I have another script that counts how many days have passed since the game has started, and it has a very simple logic: each action the user takes, a counter goes up, and when the counter reaches 3, a day passes. and by the end of each day, a new location is assigned. Here is the script for the transporting:
//Create 5 random locations where every character will be translated
public float number;
public Transform pos1;
public Transform pos2;
public Transform pos3;
public Transform pos4;
public Transform pos5;
public float newCount;
void Start()
{
number = Random.Range(1, 5);
GameObject gameClockObject = GameObject.Find("GameClockObject");
GameClock gameClock = gameClockObject.GetComponent<GameClock>();
newCount = gameClock.dayCount;
}
void Update()
{
if (number == 1)
{
transform.position = pos1.transform.position;
Debug.Log("Position 1");
}
if (number == 2)
{
transform.position = pos2.transform.position;
Debug.Log("Position 2");
}
if (number == 3)
{
transform.position = pos3.transform.position;
Debug.Log("Position 3");
}
if (number == 4)
{
transform.position = pos4.transform.position;
Debug.Log("Position 4");
}
if (number == 5)
{
transform.position = pos5.transform.position;
Debug.Log("Position 5");
}
GameObject gameClockObject = GameObject.Find("GameClockObject");
GameClock gameClock = gameClockObject.GetComponent<GameClock>();
if (newCount != gameClock.dayCount)
{
number = Random.Range(1, 5);
newCount = gameClock.dayCount;
Debug.Log("It changed");
}
}
}
I use the “newCount” variable, to compare to the previous value of the dayCount variable, and each time it changes, the location of the NPCs changes too.
The problem is that inside the Console, I keep getting this:
(Check the attached file)
(The 276 messages on the right side of the screen, that tells me the “if” statement is still running). This doesn’t stop the game from working, but please notice that that number is only 276 because I paused the game, If I had kept running it, the number would increase. I’m afraid this might create an optimization problem, and somewhere in my mind I know that the solution is very simple, but I just can’t think of it.
Could you guys help, please?