How do I perform every n-point game score?

Asked 2 years ago, Updated 2 years ago, 45 views

I'm creating a game to defeat the enemy. I'd like to create a function to raise the enemy's spawn value every time I get a score of 20, but I don't know what to do every time I get a score of 20, so please let me know.

c# unity3d

2022-09-30 11:08

2 Answers

Spawn-managed Spawner objects
GameSystem object that summarizes residual machine score pause control flags etc. Assume you have

Spawner only needs to reference the GameSystem object.
The code that changes Spawner's behavior depending on the score is Spawner's own behavior, so

in the Spawner.Move logic (MonoBehavior.Update if you are using it directly) Check GameSystem.Score and change the spawn control parameters when the conditions are met.


2022-09-30 11:08

Method 1: If you want to add one point at a time, you can use the remainder of the division.

int score;

voidAddScore()
{
  int n = 20;

  score++;
  if(score%n==0)
  {
    AddSpawnRate();
  }
}

Method 2: Introduce variables for determination if additional points change.

int score;
int bucket;

voidAddScore(int value)
{
  int n = 20;

  score+=value;
  bucket+=value;
  while(bucket>=n)
  {
    bucket-=n;
    AddSpawnRate();
  }
}


2022-09-30 11:08

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.