如何從隨機範圍1隨機ballValue爲100,每個球帶有不同價值 隨機值對象我想從範圍1隨機ballValue至100
using UnityEngine;
using System.Collections;
public class HT_Score : MonoBehaviour {
public GUIText scoreText;
public int ballValue;
private int score;
void Start() {
score = 0;
UpdateScore();
}
void OnTriggerEnter2D (Collider2D other) {
score += ballValue;
UpdateScore();
}
void OnCollisionEnter2D (Collision2D collision) {
if (collision.gameObject.tag == "Bomb") {
score -= ballValue * 2;
UpdateScore();
}
}
void UpdateScore() {
scoreText.text = "SCORE:\n" + score;
}
}
我給你一個提示:搜索'Random'。 –
可能的重複[如何在C#中使用隨機數?](http://stackoverflow.com/questions/3217651/how-do-i-use-random-numbers-in-c) – InitLipton