- Home /
Increase difficulty Space Shooter
I'd like to increase the difficulty of the Space Shooter from the Unity learn section by increasing the speed of the hazards after every wave, but the wavespawn is controlled by the GameController script, while the speed of the asteroid is controlled by anoter script, how do I access and change the speed variable from the other script? (I'm using C#).
Answer by PetterL68 · Jan 12, 2019 at 06:26 PM
I struggle with the same thing. On how to initiate the changes of in level difficulty. I have added one asteroide type more that is bigger and harder to break. Spinns slower. But everything comes at random as instructed in the tutorial.
My next is that I change all that and start easy and more problems comes later as the player progress. But dont know where to start to do it
Answer by badadam · Jan 12, 2019 at 07:58 PM
Use static value for astroid speed. If you use static value for speed, all astroid objects using same script as a component use same value. When you change static speed, it changes for all astroids.
public class AstroidScripts : MonoBehaviour {
//Add this script to all astroids
public static float astroidSpeed;
private void Update()
{
//use astroidSpeed static value
}
}
public class OtherScript : MonoBehaviour {
public void setLevel(float speed)
{
//change the level by changing astroidSpeed like this
AstroidScripts.astroidSpeed = speed;
}
}
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Lasers wont stop firing?? 1 Answer