Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by Griefer_Denis_57 · Sep 16, 2016 at 08:36 AM · c#unity 5object3d text

add 3d text through script on a object

is it possible to add a 3d text on an object which was spawned through a script for example,

GameObject sphere = GameObject.CreatePrimitive (PrimitiveType.Sphere);

can you add a 3d text above it through script?

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by NerdClown · Sep 16, 2016 at 08:47 AM

If I were you, I'd make a prefab with your primitive and a text mesh placed under it, and then instantiate the prefab from script.

You CAN also create your sphere, create an empty game object, put a text mesh component on there, put a mesh renderer component on there, set the text game object's parent to the sphere game object's transform and then put in the local coordinates for the text mesh that will make it be above the sphere. I guess that would work, never tried it. Seems like a lot of work!

In most cases I think the prefab solution would be better. There's some docs on instantiating prefabs at runtime here

Comment
Add comment · Show 3 · 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
avatar image Griefer_Denis_57 · Sep 16, 2016 at 09:13 AM 0
Share

my program will spawn multiple spheres at random locations the location is set, is there a way to do this purely through script?

avatar image NerdClown Griefer_Denis_57 · Sep 16, 2016 at 10:16 AM 0
Share

There definitely is! At work now, I will try to find time to provide an example later, if no-one beats me to it :)

avatar image NerdClown Griefer_Denis_57 · Sep 16, 2016 at 04:34 PM 1
Share

Here we go

 using UnityEngine;
 using System.Collections;
 
 public class SpawnStuff : $$anonymous$$onoBehaviour {
 
     public float  x$$anonymous$$in = -50, y$$anonymous$$in = -50, z$$anonymous$$in = -50, 
                   x$$anonymous$$ax = 50, y$$anonymous$$ax = 50, z$$anonymous$$ax = 50;
 
     public GameObject objectToSpawn;
     public int numberOfObjectsToSpawn = 40;
 
     void Start () 
     {
         for (int i = 0; i < this.numberOfObjectsToSpawn; i++)
         { 
             Vector3 position = new Vector3(Random.Range(x$$anonymous$$in, x$$anonymous$$ax), Random.Range(y$$anonymous$$in, y$$anonymous$$ax), Random.Range(z$$anonymous$$in, z$$anonymous$$ax));
 
             GameObject instantiatedObject = (GameObject)Instantiate(this.objectToSpawn, position, Quaternion.identity);
 
             instantiatedObject.name = "Object number " + i;
         }
     }
 }
 

You need to make a prefab (drag a sphere from the hierarchy into the project window). Then you need to put the script on something (for instance an empty game object) and then drag your new prefab onto the right place on the script on the empty game object.

You CAN also do it with only CreatePrimitive, but I'd recommend the instantiate prefab way because you have so many more options for changing your prefabs without having to change your already-working code.

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

254 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

how do i rotate an object? C# 1 Answer

I want to spawn objects probabilistically. 0 Answers

Swing on z axis 0 Answers

Destroy moving objcts through touch on screen 0 Answers

I'm having a problem while jumping an object in Unity 5 0 Answers


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