Number rain background

Hello everybody,

I’m really new to Unity 2017.3 and I’m currently working on a mobile platformer with the tilemap system and i want to implement a background that drops random prime numbers.

I struggle with the problem that i dont know how to make different numbers to fall down.

Also my idea is to drop some farer away (smaller) and make them fall slower so it gives the game more depth.

How do i give the spawner a list from wich it randomly picks prime numbers in different scaling sizes and different falling speeds?

Can I make one Spawner for all or should i make one spawner for each size for the numbers?

I hope you understand my question and you can help me with my problem.

Thank you very much.

Hello,

You may take a look at “3d Text” object in Unity (here some doc) :

Unity - Manual: Text Mesh component (legacy)

Unity - Scripting API: TextMesh

You could intantiate 3d object where you want and a some gravity or physics to make them fall.

In my opinion only one script is needed, it will manage the creation, fall, scale, number, etc…

I may help you with scripting if you want :slight_smile:

So this is the code for the Rain Spawner :

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PrimeRain : MonoBehaviour {

	public GameObject text3DPrefab;
	public Transform text3DContainer;

	Vector3 instanciatePosition;

	int numberToDisplay;

	// values for Rigidbody mass
	public int massMin;
	public int massMax;

	// values for Scale Range
	public int scaleXmin;
	public int scaleXmax;

	public int scaleYmin;
	public int scaleYmax;

	public int scaleZmin;
	public int scaleZmax;

	void Update() {
		// Position for Spawn
		instanciatePosition = new Vector3 (Random.Range (transform.position.x - 13, transform.position.x + 13), transform.position.y + 9, Random.Range (transform.position.z -1, transform.position.z -5));

		// Find a Number
		numberToDisplay = Random.Range (0, 9);

		// Create a new 3D Text Object from Prefab
		GameObject go = Instantiate (text3DPrefab, instanciatePosition, Quaternion.identity, text3DContainer);

		// Set the Text to display in the 3D Text
		go.GetComponent<TextMesh> ().text = numberToDisplay.ToString ();

		// List of Colors
		List<Color> listColor;
		listColor = new List <Color> ();
		listColor.Add (new Color (0, 0, 0));
		listColor.Add (new Color (0, 0, 0));
		listColor.Add (new Color (0, 0, 0));
		listColor.Add (new Color (0, 0, 0));
		listColor.Add (new Color (0, 0, 0));
		listColor.Add (new Color (0, 0, 0));
		listColor.Add (new Color (0, 0, 0));
		listColor.Add (new Color (0, 0, 0));

		// Get the Color from List
		go.GetComponent<TextMesh> ().color = listColor [Random.Range (0, listColor.Count - 1)];

		// Get Mass for Rigidbody
		go.GetComponent<Rigidbody> ().mass = Random.Range (massMin, massMax);

		// Get Scale for Object
		go.transform.localScale = new Vector3 (Random.Range (scaleXmin, scaleXmax), Random.Range (scaleYmin, scaleYmax), Random.Range (scaleZmin, scaleZmax));
	}
}

i’ve made a 3D Cube and a 3D Text and made a Prefab of it and assigned it to the Script.
And then assigned the script to the Main Camera.
When i press Play nothing happens.
The Colors are just for testing set to the same.