• 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 moheydy · Oct 15, 2018 at 03:07 AM · vector3destroydestroy objectmovetowardslinerender

how to stop vector3.MoveTowards() and Destroy Linereander

I can't stop line.setposition() I want to destroy all of Linerender, I get this error: The object of type 'LineRenderer' has been destroyed but you are still trying to access it. I want to destroy lineRender but I can't, how I can to destroy line render?? i have a key search but i dont know how to use this I use this code for destroying in other class :

private void searchName(string name) {
//befor create new path delete pervious path foreach (Transform child in parentPaths.transform) { GameObject.Destroy(child.gameObject); } objectLineRender2.startSearch(name); }

and this is my Draw() function :

private IEnumerator Draw(Vector3[] x,string s,LineRenderer line,string typePath,bool lastPath,Gradient gradient,int way) { if (typePath == "multiple") listRoW[way]++;

     listOpenPath[way] = false;
   //  this.line.colorGradient = gradient;
     int index = 1;
     int vertexPos = 1;
     // Set the LineRenderer basics with 2 vertices
     GameObject lightGameObject = new GameObject(s);
     lightGameObject.transform.parent = this.transform;
     line = lightGameObject.gameObject.AddComponent<LineRenderer>();
     line.widthMultiplier = 2.0f;
     line.positionCount = 2;
     line.material = new Material(Shader.Find("UI/Default"));
     line.colorGradient = gradient;
  
   
     // Set both point at same starting position   
     line.SetPosition(0, x[0]);
     line.SetPosition(1, x[0]);
     Vector3 temp = x[0];        // Get the current vertex position
     Vector3 target = x[index];  // Get the target vertex position
     while (true)
     {
         // Move the current pos to the target pos
         if (!keysearch) { } 
         temp = Vector3.MoveTowards(temp, target, Time.deltaTime * this.step);
         line.SetPosition(vertexPos, temp);
         
         // Is the target reached
         if (temp == target)
         {
             // This is for final run when closing the shape
             // It means we reach target and index is 0 so end of shape
             // Break the coroutine
         /*  if (index == 0)
             {
                 li.loop = true;  // Could not test this one on 5.5                  
                
             }*/
             // Increase the LineRenderer size by 1
             vertexPos++;
             if (index < x.Length - 1)
             {
                 line.positionCount++;
                 // Place the new vertex at the position of the previous
                 line.SetPosition(vertexPos, temp);              
             }

             // Increase the index and check if we reached the end of the vertex list
             // If end of vertex list, then we use the first one to close
             if (++index == x.Length)
             {
              //  index = 0;
                 if (typePath == "one") { listRoW[way]++; }

                 if (lastPath == true)
                 {
                     listOpenPath[way] = true;
                 }                    
                 yield break;
             }
             // Set new target
             target = x[index];             
         }            
        yield return null;
     }        
 }


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

0 Replies

· Add your reply
  • Sort: 

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

117 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

Related Questions

If (transform.position == Vector3.MoveTowards (transform.position, Vector3.zero, Time.deltaTime)) {...} 2 Answers

Unity 5 C# - MoveTowards is only moving in a single direction 1 Answer

Cannot remove sprite using destroy 1 Answer

Best way to make conveyer belts in C#? 1 Answer

Destroy Clone when colliding with 2d box collider 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