Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
1
Question by sebascontra · Jun 04, 2012 at 05:00 PM · c#sphereprimitives

[C#] how to add a primitive in this script???

Hi everyone, I working on a project trying to plot a nodes-edges representation but right now it just renders edges... how can I add a sphere primitive as node to get both gameObjects??

here is the script:

 // nodes
 foreach (Transform location in subregion)
 {
     try 
     {
         int nodeindex = System.Convert.ToInt16(location.gameObject.name);
         atlasRegionSubregionLocation currentNode  = connectomeModel.NodesGlobalIndexer[nodeindex] as atlasRegionSubregionLocation;
         
         int edgeinstanceIndex = 0; 
         
         foreach (int edgeIndex in currentNode.EdgeTo)
         {
             ConnectomeModel.Edge currentEdge = connectomeModel.Edges[edgeIndex];
             
             // Look for gameobjects representing edges
             Vector3 fromCoord = (GameObject.Find(currentEdge.NodeFrom.ToString())).transform.position;
             
             //should be here??                    
             GameObject sphere = (GameObject.CreatePrimitive(PrimitiveType.Sphere.currentEdge.NodeFrom.ToString())).transform.position;
 
             // transform to local region
             fromCoord = fromCoord - subregion.transform.position;
             Vector3 toCoord =  (GameObject.Find(currentEdge.NodeTo.ToString())).transform.position;
             toCoord = toCoord - subregion.transform.position;
             instanceEdge(fromCoord , toCoord , (float)currentEdge.Weight  * 1.5f +  0.5f, edgeinstanceIndex, ref tempEdges, ref tempTriangles);
             edgeinstanceIndex++;
         }
     [...]

thanks in advance

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

3 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by rutter · Jun 04, 2012 at 05:22 PM

Looks like you're created a new primitive, here:

 GameObject sphere = (GameObject.CreatePrimitive(PrimitiveType.Sphere.currentEdge.NodeFrom.ToString())).transform.position;

Problem with that, though, is you don't seem to be setting the new GameObject's position. It might also be a good idea to parent it to some other object, to keep your scene hierarchy organized. Both of these can be achieved through the new object's transform.

You can see some simple examples here.

If this is an editor-only feature you're looking into, you might also consider using Gizmos to draw spheres, lines, and so on.

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
avatar image
0

Answer by Wolfram · Jun 04, 2012 at 07:41 PM

 GameObject sphere = (GameObject.CreatePrimitive(PrimitiveType.Sphere.currentEdge.NodeFrom.ToString())).transform.position;

Umh, this line doesn't make sense, this won't even compile. You're trying to dereference "PrimitiveType.Sphere", and casting the transform.position to a GameObject...

Try something like this:

 GameObject sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere);
 sphere.transform.position=fromCoord;
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
avatar image
0

Answer by sebascontra · Jun 04, 2012 at 08:15 PM

hey! i just realized that, thanks! now I want to assign a certain size to the spheres and parent them to an empty object, but it doesn't work yet...

any idea?

Comment
Add comment · Show 2 · 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 Wolfram · Jun 04, 2012 at 08:26 PM 1
Share

Please don't add comments (and especially new questions) as answers. Add them as comments.

Just as you can set sphere.transform.position of your newly created spheres, you can set sphere.transform.localScale and sphere.transform.parent.

avatar image sebascontra · Jun 04, 2012 at 09:27 PM 0
Share

ok, cool! thanks!

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

How to find the radius area of linerencderer drawn circle and move objects inside ? 1 Answer

Simple sphere rotation gets wonky over time 1 Answer

Illuminating a 3D object's edges OnMouseOver (script in c#)? 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