Speed up Gameobjects Based on Score
I have been trying to increase the speed of some gameobjects to make my game more difficult. The more points the player scores the faster the game gets. I want the speed to remain at the incremented amount and continue to increase the higher the score.
The way my code is set up right now:
GameObject starts at normal speed and then speeds up for a second. Once the gameobject is destroyed the same thing occurs. It looks terrible!
What could I do to fix this? There are no tutorials online for this and I have tried searching unity answers for a few days and still nothing.
Here's my code:
Object Spawner:
using UnityEngine;
using System.Collections;
public class NewEnemySpawner : MonoBehaviour {
public Transform []spawnPoints;
public float spawnTime = 2f;
public GameObject [] Players;
//public float moveSpeed;
// Use this for initialization
void Start () {
InvokeRepeating ("SpawnPlayers", spawnTime, spawnTime);
}
// Update is called once per frame
void Update () {
}
void SpawnPlayers(){
int spawnIndex = Random.Range (0, spawnPoints.Length);
int objectIndex = Random.Range (0, Players.Length);
Instantiate (Players [objectIndex], spawnPoints [spawnIndex].position, spawnPoints [spawnIndex].rotation );
}
}
My Attempt at Increasing the Speed Based on Score:
using UnityEngine;
using System.Collections;
public class RunningPlayersRight : MonoBehaviour {
public GameObject runningPlayer;
//public Vector3 target;
public float speed=1.0f;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (ScoreManager.scoreCount % 100 == 0) {
speed += .05f;
}
float change = speed * Time.deltaTime;
runningPlayer.transform.Translate(Vector3.left *change );
//transform.position = Vector3.MoveTowards (transform.position, target, change);
Destroy (gameObject,4);
}
}
Hey your spawner script is almost exactly like $$anonymous$$e:)
I'm not exactly clear on what you're trying to do. So what you want is the speed of some gameobjects to go faster when you have a higher score but they don't slow down?
If that's the case I would just get every time the score goes up and add a value to the gameobject's speed.
Did you manage to do it in the end? if yes, can you write how you did it, thanks. @El-Deiablo,Did you manage to do it in the end? If yes, can you tell me how you did it, thanks.
Your answer
![](https://koobas.hobune.stream/wayback/20220612081810im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
game object attached to the cursor moving too slow 1 Answer
Making someone happen after x amounts of seconds and only once 0 Answers
How Do I Change UI Image Anchor Position To Hover Over GameObject? 1 Answer
Make a object always appear behing another object 1 Answer
How to put ".transform" after "GameObject.FindGameObjectsWithTag()" 1 Answer