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
0
Question by Luci85 · Apr 05, 2012 at 05:11 PM · prefabinstanceindependent

Moving a single instance

I draw a line on which I want to add "handles", these "handles" can be moved and leave a line from their respective anchorpoint, to the new position of their respective "handle". So I made a prefab "handle" which gets instantiated on the line after a certain distance from the last "handle" was drawn. Each handle should be able to move independently, because I want to use the line length for other calculations. But when I have more than 1 instance, all overlap when I try to move a single "handle".

Here's some code to elaborate:

 var rubberBand:GameObject;
 private var uniqueRubberBand:GameObject;
 private var rubberBandName:String;
 uniqueRubberBand = Instantiate(rubberBand, Vector3(linepos.x, linepos.y + 5, linepos.z),  transform.rotation);
 rubberBandName = "RubberBand";
 rubberBandName = rubberBandName.Insert(rubberBandName.Length, rubberBandNameArray.length.ToString());

Now for the line drawing, that is happening in a script attached to the prefab:

 function Start () 
 {
     anchor = transform.position;
     drag = false;
     //Line1
     line = new LineRenderer();
     line = gameObject.AddComponent(LineRenderer);
     material = new Material(Shader.Find("Diffuse"));
        material.color = Color.red;
     line.material = material;
     line.SetVertexCount(0);
     line.SetWidth(startWidth, endWidth);
     //Line2
     lineHelper2 = new GameObject();
     lineHelper2.name = this.name + "lineHelper2";
     line2 = new LineRenderer();
     line2 = lineHelper2.AddComponent(LineRenderer);
     line2.SetVertexCount(0);
     line2.SetWidth(startWidth, endWidth);
     material2 = new Material(Shader.Find("Diffuse"));
     material2.color = Color.blue;
     line2.material = material2;
     //Line3
     ...
 }
 function Update()
 {...
             line.SetVertexCount(2);
             line.SetPosition(0, anchor);
             line.SetPosition(1, anchor + unitVector * 25);
             line2.SetVertexCount(2);
             line2.SetPosition(0, anchor + unitVector * 25);
             line2.SetPosition(1, anchor + unitVector * 50);
             line3.SetVertexCount(2);
             line3.SetPosition(0, anchor + unitVector * 50);
             line3.SetPosition(1, transform.position);
     ...}
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
0
Best Answer

Answer by Luci85 · Apr 05, 2012 at 06:53 PM

Just found the solution: Make a raycast and test if the hit is the instance itself and not something else.

 if (Physics.Raycast (ray, hit, Mathf.Infinity))
 if(hit.transform.name == this.name)
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

Affect All Instances Of A Prefab 3 Answers

How to remove a specific instance of a prefab from List? 1 Answer

Gameobject missing camera when instance prefab 3 Answers

How can I set the material on an instance after creating it? 1 Answer

How can I link a GameObject instance to a script variable in a Prefab using the editor? 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