Hello! This question should be rather short (and sweet!). I have an enemy type in my game dropping a random set of coins Range(1,10). Problem is, they all go the same way for my "coin.rigidbody2D.AddRelativeForce(randomDirection);". I thought it would go through the for-loop differently each time. How do i go about making it so?
private int numberOfCoins;
void Start() {
numberOfCoins = Random.Range(1,10);
}
void LateUpdate() {
[...]
Vector2 randomDirection = new Vector2(Random.Range(-800f, 800f), Random.Range(-800f, 800f));
GameObject coin;
for (int i = 0; i < numberOfCoins; i++) {
coin = (Instantiate(coinPrefab, enemy.transform.position, enemy.transform.rotation)) as GameObject;
coin.rigidbody2D.AddRelativeForce(randomDirection);
}
↧