I need a targeting system where an enemy unit choose a random unit (with a unique percent value) from a unit group and attack that unit. This system must apply to groups of any size and the total percent value of all units combined must add up to 100%.
Example:
Lets assume there are 3 available targets, each with a unique percent chance of being attacked.
Unit 1: 50% to be hit
Unit 2: 30% to be hit
Unit 3: 20% to be hit
I want the enemy to have 50% chance of attacking Unit 1, 30% chance of attacking unit 2 and 20% chance to attack unit 3.
How can I do this?
Example:
Lets assume there are 3 available targets, each with a unique percent chance of being attacked.
Unit 1: 50% to be hit
Unit 2: 30% to be hit
Unit 3: 20% to be hit
I want the enemy to have 50% chance of attacking Unit 1, 30% chance of attacking unit 2 and 20% chance to attack unit 3.
How can I do this?