How to give points after certain number of seconds?,How to give points after a certain number of seconds?

Hi everyone! So basically i made the whole game and its almost ready, but one of the few scripts that i need is a score script, but unlike other little project i made, this one is making me struggling for almost a week now…what i want is this: Make a script where once the player starts moving, it starts a timer, and every three seconds, if the player has not died yet, it recieves 10 points.

Now, i have tried with coroutines, while loops…but nothing seems to work? Maybe i’m writing something wrong…i really hope one of you can help me out with this one!,Hi everyone! So i basically made the whole game (i’m a beginner but with a little bit of experience, still learning tho) and the only script that i need to finish the beta is a score script… its almost a week i’m struggling make a script like this:

Make a script where when the player starts moving, it starts a timer. And every three seconds, if the player has not died yet, it gives 10 points.

Now, i tried with coroutines, while loops…but nothing seems to work! Hope some of you can help me out with this one :slight_smile:

You were correct by using coroutines, but there may have been an error in your logic. Here is an example for your situation:

//I don’t know how you get your player movement, so I’ll put a bool that’s false until his initial start position is different from his position

bool playerMoving = false;
bool countPoints = false;
Vector3 startPos;
GameObject player;

void Start(){
player = GameObject.Find(“PlayerName”);
startPos = player.transform.position;
}

void Update(){

if( player.transform.position != startPos && !countPoints){
playerMoving = true;
}

if(playerMoving){
StartCoroutine(PointCounter());
countPoints = true;
    playerMoving = false; //set to false to ensure you don’t start multiple coroutines
}
}

int pointCounter;

IEnumerator PointCounter(){

while(countPoints){
yields return new WaitForSeconds(3);
pointCounter = pointCounter + 10; //add to score
}
}

Hope that helps