Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by mail2sawan · Aug 05, 2015 at 09:01 AM · positiontextvector3

Display text on Cloud sprites

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[i] = Instantiate(collectables[i]) as GameObject;
             collectables[i].SetActive(false);
         }
 
     }
 
 
     // Use this for initialization
     void Start () {
 
         playerScript = GameObject.Find ("Player").GetComponent<Player> ();
         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 [i].activeInHierarchy) {
                     temp.x = Random.Range (minX, maxX);
 
                     temp.y -= distanceBetweenClouds;
                     
                     lastCloudPositionY = temp.y;
                     
                     
                     clouds [i].transform.position = temp;
                     clouds [i].SetActive (true);
 
                     int random =Random.Range(0, collectables.Length);
 
                     if (clouds[i].tag != "Deadly"){
 
                         //if(!collectables[random].activeInHierarchy){
                         //    collectables[random].SetActive(true);
                         //    collectables[random].transform.position = new Vector3 (clouds[i].transform.position.x - 0.2f,
                         //                                                           clouds[i].transform.position.y + 0.7f,
                         //                                                           clouds[i].transform.position.z);
 
 
                         //}
 
                     }
                 }
             }
         }
     }
 
 
 
     void CreateClouds(float positionY) {
 
         Shuffle (clouds);
 
         for (int i = 0; i < clouds.Length; i++) {
 
             clouds [i] = Instantiate (clouds [i], Vector3.zero,Quaternion.identity) as GameObject;
             Vector3 temp = clouds [i].transform.position;
 
             float randomX = Random.Range (minX, maxX);
 
             temp.x = randomX;
             temp.y = positionY;
             
             lastCloudPositionY = temp.y;
             
             clouds [i].transform.position = temp;
             
             positionY -= distanceBetweenClouds;
 
         }
     }
 
     void Shuffle(GameObject[] array) {
         
     
         for(int i = 0; i < array.Length; i++) {
             
             GameObject temp = array[i];
             int random = Random.Range(i, array.Length);
             array[i] = array[random];
             array[random] = temp;
 
             
         }
         
     }
     
 }
Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image mail2sawan · Aug 05, 2015 at 12:37 PM 0
Share

Anybody???

avatar image mail2sawan · Aug 17, 2015 at 08:23 AM 0
Share

No one!!!!

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Arshia001 · Aug 17, 2015 at 09:27 AM

Add a canvas text or a text mesh to the cloud objects. Also, you should generally try and watch a few video tutorials.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Cannot implicitly convert type 'int' to 'UnityEngine.Vector3' 3 Answers

how to scale and position guiText in android 1 Answer

split vector3 coordinates in to x,y,z 1 Answer

Add posititons relative to transform 2 Answers

How to detect if transform.position is not vector3 + 100 on x position 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges