- Home /
how to make a progressive/dynamic integer
i want to make a random int in between 0 and the array length and the level number so the more higher the level the more harder the enemy is in the array or the more higher the array count is but when it reaches the max in the array length i want it to stop which i could do with
if(currentprogressionint <= enemy.length){ //stop }else{ //progression mark }
The if would be something like int result = Random.Range(currentProgressionInt, enemy.Length);
I think you meant stop if currentProgressionInt >= enemy.Length
@hexagonius umm i didnt want a random int i want something like the more higher level the more harder the prefab is spawned based on the array index
If you organise your enemy array based on difficulty that's exactly what a random int will give you.
If this is not what you want, please rephrase your question and add more information.
Answer by Harinezumi · Mar 17, 2018 at 10:03 AM
Please update the question with more information. It is still not clear what is it exactly that you would like to achieve.
If you want to generate monsters at most the current level difficulty, then the following code will work:
enemyIndex = Random.Range(0, Mathf.Min(currentProgressionInt + 1, enemy.Length)); // +1 needed to include currentProgressionInt as possible value
ask it in a answer and i will accept it as it seems like it worked
Answer by tormentoarmagedoom · Mar 16, 2018 at 09:49 AM
Good day.
You need to use this tools:
Random.Range (To random select a number from a minimum to a maximum)
Array.Lenght (Determinate the number of elements in an array)
Mathf.Max (Determinate the higher number inside an array)
Using this 3 tools you should be able to determinate what you need.
If helped, accept the answer :D
the problem with Random.Range is that it could spawn the hardest enemy on Level 1 which is a pain
Why $$anonymous$$athf.$$anonymous$$ax? If I understand it correctly, Rickasheye wants to limit from above.
Right, he needs $$anonymous$$ath.$$anonymous$$in to avoid an index out of bounds exception.
Answer by FM-Productions · Mar 17, 2018 at 10:10 AM
You could use Random.Range but you make the minimum value depending on the level. for example:
int levelNumber = ...
int enemyDiffculty = Random.Range(levelNumber, difficultyMax);
The levelNumber should not exceed the difficultyMax of course, and difficulty max can be your Array.Length value
This can cause issues if levelNumber
is less than difficulty$$anonymous$$ax
.
Your answer
Follow this Question
Related Questions
Making the floor/ground of a map 1 Answer
What is the best way to create 3D tile based levels in Unity ? 1 Answer
Collision problems with level design 1 Answer
Very weird dark level loading? 4 Answers
Level designer Méthode question 2 Answers