How to assign numbers to objects?

Hi, Currently my game consistently spawns objects for a player to dodge, but I need each one of these objects to have a random number between say 1 and 100 visible on the object. I need to be able to track which number the player has just hit as well. Any ideas on how I could do this?

Make a script that gets attached to each of your random objects; give that script an int called myNumber. Then give it a random integer between 1 and 100 using its Awake() method.

public class NumberHolder : MonoBehaviour {
   int myNumber = 0;
   UnityEngine.UI.Text myTextField;
   void Awake() {
      myNumber = UnityEngine.Random.Range(0,100) + 1;
      myTextField = GetComponent<UnityEngine.UI.Text>();
   void Start() {
      if(myTextField != null) {
         myTextField.text = "" + myNumber;

Then when you “hit” an object, read the number myNumber off of the NumberHolder script attached to that object. Store it in some other script that you have attached to your scene.

edited to display this in the object’s text field; you’ll need to check out the docs to figure out how to get it locked to your 3D objects.