So, i’m stuck. Again.
Okay, I have a variable that I want to pass through a method. However, this variable is meant for more than one object, so i’m using a foreach loop. Now, I want this variable to have a random value between 2 numbers, and it has to be random for each object. The value is random, yes, but when that one number is decided by the script, ALL the objects get the same value, since the code inside the foreach loop asks only for the value of “rdmValue”.(Check below) I’d like my script to make new values for each object.
-
This is the value I want to pass:
rdmValue = Random.Range(0, 11); -
Let’s say “rdmValue” equals 4. Now all the objects will get a 4, even though I want all of them to get a random value.
foreach (GameObject object in enemyList)
{
object.GetComponent().ReceiveDamage(rdmValue);
}
Please, let me know if you didn’t get something from what I typed(my English is not too great). Thank you!