Hi,
I’m working on a game and I’m on the enemy script. I don’t really need a script help, but a method help. And really, I don’t need any “buy this asset answer”, I would like to make it by my own. I’m working on the attack part, I would like to put some kind of “priority” in the attack list. For example, the enemy is like : Ok, I’m gonna kill you so, I prefer burn your body instead of crushing it. And then it fires.
I need to make an attack selection according to a priority. RPG builders maybe know what I’m talking about.
I don’t know how to make a random number yet but it what I’m looking for :
generating random number
according to priority you have more chance to make your prefered attack.
I think the RPG builders and paper RPG players have a kind of math trick for it and I would like to learn it.
To generate a random number you could use Random.Range Unity - Scripting API: Random.Range
As for the attack priority, there’s no trick here. And actually it’s not random, but just the opposite.
The enemy will have a script attached to it that handles the logic of attacking. Let’s say for example that the enemy has two kinds of attacks - a spell area of effect attack and a regular physical attack. How does the enemy choose which one to use? This will be done by you in the script. You could do something like this, in psuedo-code
if (players are closely bunched up enemy has enough mana)
attack.spell(aoe)
else
targetClosestPlayer()
attack.regular()
You understand?
Yep, it is already what I’ve done to select between melee or range attack. Sorry but it was not explained, I would like to use a random choice for all melee attacks available I mean.
For example, the enemy can hit the player with hand or with kick, if it prefers kicks it will use kick attack more frequently than punches.
I mean, I can use random number 0 to 10, if it is more than 5 then kick, less than punch, if I would like more chance to select kicks, I have to put a higher range in random value like 3 to 10 for kicks and 0 to 2 for punches. It works fine with 2 attacks, I would like to know, if there is a method to apply it to n attacks with p percents of chance to select it.
FOUND 
I will post the code if someone would like it.
It is not the best way to do it I think but I have this method :
First create the attack class with priority, prioritymin, prioritymax in variables
Create a list of attack class
Create a totalpriority number var
for each attack in attack list
attack.prioritymin=totalpriority
totalpriority+=attack.priority
attack.prioritymax=totalpriority
All priority has been computed
now check wich attack to use
Create a var num = random.range(0 ,totalpriority)
for each attack in attack list
if num>=attack.prioritymin num <= attack.prioritymax
use attack selected
AND ITS DONE
… I hope
i have to try first…