By the following script I randomly spawning my clouds into the screen. Now I want to display some text on cloud sprite. Text will be different for every cloud and move with the cloud. Please help me out how can I do this?
using UnityEngine;
using System.Collections;
public class CloudSpawnerScript : MonoBehaviour {
[SerializeField]
private GameObject[] clouds;
public float distanceBetweenClouds = 2.0f;
public static float minX, maxX;
private Player playerScript;
public float lastCloudPositionY;
[SerializeField]
private GameObject[] cloudsInGame;
[SerializeField]
private GameObject[] collectables;
public float lastPositionX;
private int controllX;
void Awake(){
Vector2 t = Camera.main.ScreenToWorldPoint (new Vector2 (Screen.width, Screen.height));
maxX = t.x - 0.5f;
minX = -t.x + 0.5f;
float center = Screen.width / Screen.height;
CreateClouds (center);
for (int i = 0; i < collectables.Length; i++) {
collectables _= Instantiate(collectables*) as GameObject;*_
_ collectables*.SetActive(false);
}*_
* }*
* // Use this for initialization*
* void Start () {*
* playerScript = GameObject.Find (“Player”).GetComponent ();*
* cloudsInGame = GameObject.FindGameObjectsWithTag (“Cloud”);*
* Vector3 temp = new Vector3 (cloudsInGame [0].transform.position.x, cloudsInGame [0].transform.position.y + 0.6f, playerScript.transform.position.z);*
* playerScript.transform.position = temp;*
* }*
* void OnTriggerEnter2D(Collider2D target) {*
* if (target.tag == “Deadly” || target.tag == “Cloud”) {*
* Vector3 temp = target.transform.position;*
* Shuffle (clouds);*
* for (int i = 0; i < clouds.Length; i++) {*
_ if (!clouds .activeInHierarchy) {
* temp.x = Random.Range (minX, maxX);*_
* temp.y -= distanceBetweenClouds;*
* lastCloudPositionY = temp.y;*
_ clouds .transform.position = temp;
clouds .SetActive (true);_
* int random =Random.Range(0, collectables.Length);*
_ if (clouds*.tag != “Deadly”){*_
* //if(!collectables[random].activeInHierarchy){*
* // collectables[random].SetActive(true);*
_ // collectables[random].transform.position = new Vector3 (clouds*.transform.position.x - 0.2f,
// clouds.transform.position.y + 0.7f,
// clouds.transform.position.z);*_
* //}*
* }*
* }*
* }*
* }*
* }*
* void CreateClouds(float positionY) {*
* Shuffle (clouds);*
* for (int i = 0; i < clouds.Length; i++) {*
clouds = Instantiate (clouds , Vector3.zero,Quaternion.identity) as GameObject;
_ Vector3 temp = clouds .transform.position;_
* float randomX = Random.Range (minX, maxX);*
* temp.x = randomX;*
* temp.y = positionY;*
* lastCloudPositionY = temp.y;*
_ clouds .transform.position = temp;_
* positionY -= distanceBetweenClouds;*
* }*
* }*
* void Shuffle(GameObject[] array) {*
* for(int i = 0; i < array.Length; i++) {*
_ GameObject temp = array*;
int random = Random.Range(i, array.Length);
array = array[random];
array[random] = temp;*_
* }*
* }*
}